Average Error: 14.2 → 7.8
Time: 17.2s
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.25}\right)}^{\left(\mathsf{fma}\left(-2, -\log D, \log \left(\left(\frac{h}{\ell} \cdot \left(\frac{M}{d} \cdot \frac{M}{d}\right)\right) \cdot -0.25\right)\right)\right)}\right)}^{2}\\ \mathbf{elif}\;t_0 \leq 0:\\ \;\;\;\;w0 \cdot \sqrt{1 - t_0}\\ \mathbf{else}:\\ \;\;\;\;w0 \cdot \sqrt{1 + h \cdot \left(\frac{M \cdot 0.5}{\frac{d}{D}} \cdot \frac{M \cdot \left(\frac{D}{d} \cdot -0.5\right)}{\ell}\right)}\\ \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.25)
        (fma -2.0 (- (log D)) (log (* (* (/ h l) (* (/ M d) (/ M d))) -0.25))))
       2.0))
     (if (<= t_0 0.0)
       (* w0 (sqrt (- 1.0 t_0)))
       (*
        w0
        (sqrt
         (+
          1.0
          (* h (* (/ (* M 0.5) (/ d D)) (/ (* M (* (/ D d) -0.5)) l))))))))))
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.25), fma(-2.0, -log(D), log((((h / l) * ((M / d) * (M / d))) * -0.25)))), 2.0);
	} else if (t_0 <= 0.0) {
		tmp = w0 * sqrt((1.0 - t_0));
	} else {
		tmp = w0 * sqrt((1.0 + (h * (((M * 0.5) / (d / D)) * ((M * ((D / d) * -0.5)) / l)))));
	}
	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.25) ^ fma(-2.0, Float64(-log(D)), log(Float64(Float64(Float64(h / l) * Float64(Float64(M / d) * Float64(M / d))) * -0.25)))) ^ 2.0));
	elseif (t_0 <= 0.0)
		tmp = Float64(w0 * sqrt(Float64(1.0 - t_0)));
	else
		tmp = Float64(w0 * sqrt(Float64(1.0 + Float64(h * Float64(Float64(Float64(M * 0.5) / Float64(d / D)) * Float64(Float64(M * Float64(Float64(D / d) * -0.5)) / l))))));
	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.25], $MachinePrecision], N[(-2.0 * (-N[Log[D], $MachinePrecision]) + N[Log[N[(N[(N[(h / l), $MachinePrecision] * N[(N[(M / d), $MachinePrecision] * N[(M / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * -0.25), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 0.0], N[(w0 * N[Sqrt[N[(1.0 - t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(w0 * N[Sqrt[N[(1.0 + N[(h * N[(N[(N[(M * 0.5), $MachinePrecision] / N[(d / D), $MachinePrecision]), $MachinePrecision] * N[(N[(M * N[(N[(D / d), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision] / l), $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.25}\right)}^{\left(\mathsf{fma}\left(-2, -\log D, \log \left(\left(\frac{h}{\ell} \cdot \left(\frac{M}{d} \cdot \frac{M}{d}\right)\right) \cdot -0.25\right)\right)\right)}\right)}^{2}\\

\mathbf{elif}\;t_0 \leq 0:\\
\;\;\;\;w0 \cdot \sqrt{1 - t_0}\\

\mathbf{else}:\\
\;\;\;\;w0 \cdot \sqrt{1 + h \cdot \left(\frac{M \cdot 0.5}{\frac{d}{D}} \cdot \frac{M \cdot \left(\frac{D}{d} \cdot -0.5\right)}{\ell}\right)}\\


\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.9

      \[\leadsto \color{blue}{w0 \cdot \sqrt{1 - {\left(M \cdot \frac{D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}}} \]
    3. Applied egg-rr61.9

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

      \[\leadsto w0 \cdot {\color{blue}{\left(e^{0.25 \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)}}^{2} \]
    5. Simplified49.8

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

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

    1. Initial program 0.1

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

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

    1. Initial program 32.8

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

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

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

      \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\frac{{\left(M \cdot \left(0.5 \cdot \frac{D}{d}\right)\right)}^{2}}{\ell} \cdot h}} \]
    5. Applied egg-rr6.9

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

      \[\leadsto w0 \cdot \sqrt{1 - \left(\frac{M \cdot 0.5}{\frac{d}{D}} \cdot \color{blue}{\frac{M \cdot \left(0.5 \cdot \frac{D}{d}\right)}{\ell}}\right) \cdot h} \]
  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 -\infty:\\ \;\;\;\;w0 \cdot {\left({\left(e^{0.25}\right)}^{\left(\mathsf{fma}\left(-2, -\log D, \log \left(\left(\frac{h}{\ell} \cdot \left(\frac{M}{d} \cdot \frac{M}{d}\right)\right) \cdot -0.25\right)\right)\right)}\right)}^{2}\\ \mathbf{elif}\;{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell} \leq 0:\\ \;\;\;\;w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}}\\ \mathbf{else}:\\ \;\;\;\;w0 \cdot \sqrt{1 + h \cdot \left(\frac{M \cdot 0.5}{\frac{d}{D}} \cdot \frac{M \cdot \left(\frac{D}{d} \cdot -0.5\right)}{\ell}\right)}\\ \end{array} \]

Alternatives

Alternative 1
Error8.6
Cost27784
\[\begin{array}{l} t_0 := w0 \cdot \sqrt{1 + h \cdot \left(\frac{M \cdot 0.5}{\frac{d}{D}} \cdot \frac{M \cdot \left(\frac{D}{d} \cdot -0.5\right)}{\ell}\right)}\\ t_1 := {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\\ \mathbf{if}\;t_1 \leq 2 \cdot 10^{+21}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_1 \leq 5 \cdot 10^{+251}:\\ \;\;\;\;w0 \cdot \sqrt{1 - t_1 \cdot \frac{h}{\ell}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error13.4
Cost8008
\[\begin{array}{l} \mathbf{if}\;\ell \leq -1.75 \cdot 10^{-41}:\\ \;\;\;\;w0\\ \mathbf{elif}\;\ell \leq 3.1 \cdot 10^{-132}:\\ \;\;\;\;w0 \cdot \sqrt{1 + \frac{\frac{D}{d} \cdot \left(M \cdot \left(M \cdot h\right)\right)}{\frac{d}{D}} \cdot \frac{-0.25}{\ell}}\\ \mathbf{else}:\\ \;\;\;\;w0\\ \end{array} \]
Alternative 3
Error9.4
Cost7872
\[w0 \cdot \sqrt{1 + h \cdot \left(\frac{M \cdot 0.5}{\frac{d}{D}} \cdot \frac{M \cdot \left(\frac{D}{d} \cdot -0.5\right)}{\ell}\right)} \]
Alternative 4
Error10.9
Cost7744
\[\begin{array}{l} t_0 := D \cdot \frac{M}{d}\\ w0 \cdot \sqrt{1 + h \cdot \left(-0.25 \cdot \frac{t_0 \cdot t_0}{\ell}\right)} \end{array} \]
Alternative 5
Error13.7
Cost64
\[w0 \]

Error

Reproduce

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