Average Error: 14.3 → 9.4
Time: 8.0s
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}\\ \mathbf{if}\;t_0 \leq -\infty:\\ \;\;\;\;w0 \cdot \left(D \cdot \sqrt{\frac{-0.25 \cdot \left(M \cdot M\right)}{\ell} \cdot \frac{h}{d \cdot d}}\right)\\ \mathbf{elif}\;t_0 \leq 10^{-6}:\\ \;\;\;\;w0 \cdot \sqrt{1 - t_0}\\ \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))))
   (if (<= t_0 (- INFINITY))
     (* w0 (* D (sqrt (* (/ (* -0.25 (* M M)) l) (/ h (* d d))))))
     (if (<= t_0 1e-6) (* w0 (sqrt (- 1.0 t_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 tmp;
	if (t_0 <= -((double) INFINITY)) {
		tmp = w0 * (D * sqrt((((-0.25 * (M * M)) / l) * (h / (d * d)))));
	} else if (t_0 <= 1e-6) {
		tmp = w0 * sqrt((1.0 - t_0));
	} else {
		tmp = w0;
	}
	return tmp;
}
public static double code(double w0, double M, double D, double h, double l, double d) {
	return w0 * Math.sqrt((1.0 - (Math.pow(((M * D) / (2.0 * d)), 2.0) * (h / l))));
}
public static double code(double w0, double M, double D, double h, double l, double d) {
	double t_0 = Math.pow(((M * D) / (2.0 * d)), 2.0) * (h / l);
	double tmp;
	if (t_0 <= -Double.POSITIVE_INFINITY) {
		tmp = w0 * (D * Math.sqrt((((-0.25 * (M * M)) / l) * (h / (d * d)))));
	} else if (t_0 <= 1e-6) {
		tmp = w0 * Math.sqrt((1.0 - t_0));
	} else {
		tmp = w0;
	}
	return tmp;
}
def code(w0, M, D, h, l, d):
	return w0 * math.sqrt((1.0 - (math.pow(((M * D) / (2.0 * d)), 2.0) * (h / l))))
def code(w0, M, D, h, l, d):
	t_0 = math.pow(((M * D) / (2.0 * d)), 2.0) * (h / l)
	tmp = 0
	if t_0 <= -math.inf:
		tmp = w0 * (D * math.sqrt((((-0.25 * (M * M)) / l) * (h / (d * d)))))
	elif t_0 <= 1e-6:
		tmp = w0 * math.sqrt((1.0 - t_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))
	tmp = 0.0
	if (t_0 <= Float64(-Inf))
		tmp = Float64(w0 * Float64(D * sqrt(Float64(Float64(Float64(-0.25 * Float64(M * M)) / l) * Float64(h / Float64(d * d))))));
	elseif (t_0 <= 1e-6)
		tmp = Float64(w0 * sqrt(Float64(1.0 - t_0)));
	else
		tmp = w0;
	end
	return tmp
end
function tmp = code(w0, M, D, h, l, d)
	tmp = w0 * sqrt((1.0 - ((((M * D) / (2.0 * d)) ^ 2.0) * (h / l))));
end
function tmp_2 = code(w0, M, D, h, l, d)
	t_0 = (((M * D) / (2.0 * d)) ^ 2.0) * (h / l);
	tmp = 0.0;
	if (t_0 <= -Inf)
		tmp = w0 * (D * sqrt((((-0.25 * (M * M)) / l) * (h / (d * d)))));
	elseif (t_0 <= 1e-6)
		tmp = w0 * sqrt((1.0 - t_0));
	else
		tmp = w0;
	end
	tmp_2 = 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[(D * N[Sqrt[N[(N[(N[(-0.25 * N[(M * M), $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision] * N[(h / N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 1e-6], N[(w0 * N[Sqrt[N[(1.0 - t$95$0), $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}\\
\mathbf{if}\;t_0 \leq -\infty:\\
\;\;\;\;w0 \cdot \left(D \cdot \sqrt{\frac{-0.25 \cdot \left(M \cdot M\right)}{\ell} \cdot \frac{h}{d \cdot d}}\right)\\

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

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


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

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.2

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

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

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

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

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

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

    1. Initial program 0.1

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

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

    1. Initial program 62.7

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

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

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

    \[\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(D \cdot \sqrt{\frac{-0.25 \cdot \left(M \cdot M\right)}{\ell} \cdot \frac{h}{d \cdot d}}\right)\\ \mathbf{elif}\;{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell} \leq 10^{-6}:\\ \;\;\;\;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 2022192 
(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))))))