Average Error: 13.4 → 8.8
Time: 17.3s
Precision: binary64
Cost: 28296
\[ \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(\frac{0.5}{d} \cdot \sqrt{\frac{D \cdot D}{\ell} \cdot \left(\left(M \cdot h\right) \cdot \left(-M\right)\right)}\right)\\ \mathbf{elif}\;t_0 \leq 10^{-12}:\\ \;\;\;\;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 (* (/ 0.5 d) (sqrt (* (/ (* D D) l) (* (* M h) (- M))))))
     (if (<= t_0 1e-12) (* 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 * ((0.5 / d) * sqrt((((D * D) / l) * ((M * h) * -M))));
	} else if (t_0 <= 1e-12) {
		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 * ((0.5 / d) * Math.sqrt((((D * D) / l) * ((M * h) * -M))));
	} else if (t_0 <= 1e-12) {
		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 * ((0.5 / d) * math.sqrt((((D * D) / l) * ((M * h) * -M))))
	elif t_0 <= 1e-12:
		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(Float64(0.5 / d) * sqrt(Float64(Float64(Float64(D * D) / l) * Float64(Float64(M * h) * Float64(-M))))));
	elseif (t_0 <= 1e-12)
		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 * ((0.5 / d) * sqrt((((D * D) / l) * ((M * h) * -M))));
	elseif (t_0 <= 1e-12)
		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[(N[(0.5 / d), $MachinePrecision] * N[Sqrt[N[(N[(N[(D * D), $MachinePrecision] / l), $MachinePrecision] * N[(N[(M * h), $MachinePrecision] * (-M)), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 1e-12], 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(\frac{0.5}{d} \cdot \sqrt{\frac{D \cdot D}{\ell} \cdot \left(\left(M \cdot h\right) \cdot \left(-M\right)\right)}\right)\\

\mathbf{elif}\;t_0 \leq 10^{-12}:\\
\;\;\;\;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. Simplified62.1

      \[\leadsto \color{blue}{w0 \cdot \sqrt{-\mathsf{fma}\left({\left(M \cdot \frac{D}{2 \cdot d}\right)}^{2}, \frac{h}{\ell}, -1\right)}} \]
      Proof
      (*.f64 w0 (sqrt.f64 (neg.f64 (fma.f64 (pow.f64 (*.f64 M (/.f64 D (*.f64 2 d))) 2) (/.f64 h l) -1)))): 0 points increase in error, 0 points decrease in error
      (*.f64 w0 (sqrt.f64 (neg.f64 (fma.f64 (pow.f64 (Rewrite<= *-commutative_binary64 (*.f64 (/.f64 D (*.f64 2 d)) M)) 2) (/.f64 h l) -1)))): 0 points increase in error, 0 points decrease in error
      (*.f64 w0 (sqrt.f64 (neg.f64 (fma.f64 (pow.f64 (Rewrite<= associate-/r/_binary64 (/.f64 D (/.f64 (*.f64 2 d) M))) 2) (/.f64 h l) -1)))): 6 points increase in error, 4 points decrease in error
      (*.f64 w0 (sqrt.f64 (neg.f64 (fma.f64 (pow.f64 (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 D M) (*.f64 2 d))) 2) (/.f64 h l) -1)))): 4 points increase in error, 5 points decrease in error
      (*.f64 w0 (sqrt.f64 (neg.f64 (fma.f64 (pow.f64 (/.f64 (Rewrite<= *-commutative_binary64 (*.f64 M D)) (*.f64 2 d)) 2) (/.f64 h l) -1)))): 0 points increase in error, 0 points decrease in error
      (*.f64 w0 (sqrt.f64 (neg.f64 (fma.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 2 d)) 2) (/.f64 h l) (Rewrite<= metadata-eval (neg.f64 1)))))): 0 points increase in error, 0 points decrease in error
      (*.f64 w0 (sqrt.f64 (neg.f64 (Rewrite<= fma-neg_binary64 (-.f64 (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 2 d)) 2) (/.f64 h l)) 1))))): 0 points increase in error, 0 points decrease in error
      (*.f64 w0 (sqrt.f64 (Rewrite<= sub0-neg_binary64 (-.f64 0 (-.f64 (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 2 d)) 2) (/.f64 h l)) 1))))): 0 points increase in error, 0 points decrease in error
      (*.f64 w0 (sqrt.f64 (Rewrite<= associate-+l-_binary64 (+.f64 (-.f64 0 (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 2 d)) 2) (/.f64 h l))) 1)))): 0 points increase in error, 0 points decrease in error
      (*.f64 w0 (sqrt.f64 (+.f64 (Rewrite<= neg-sub0_binary64 (neg.f64 (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 2 d)) 2) (/.f64 h l)))) 1))): 0 points increase in error, 0 points decrease in error
      (*.f64 w0 (sqrt.f64 (+.f64 (Rewrite<= distribute-lft-neg-out_binary64 (*.f64 (neg.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 2 d)) 2)) (/.f64 h l))) 1))): 0 points increase in error, 0 points decrease in error
      (*.f64 w0 (sqrt.f64 (Rewrite<= +-commutative_binary64 (+.f64 1 (*.f64 (neg.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 2 d)) 2)) (/.f64 h l)))))): 0 points increase in error, 0 points decrease in error
      (*.f64 w0 (sqrt.f64 (Rewrite<= cancel-sign-sub-inv_binary64 (-.f64 1 (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 2 d)) 2) (/.f64 h l)))))): 0 points increase in error, 0 points decrease in error
    3. Taylor expanded in M around inf 62.3

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

      \[\leadsto w0 \cdot \sqrt{-\color{blue}{\frac{0.25}{d \cdot d} \cdot \left(\left(\frac{D}{\ell} \cdot D\right) \cdot \left(M \cdot \left(M \cdot h\right)\right)\right)}} \]
      Proof
      (*.f64 (/.f64 1/4 (*.f64 d d)) (*.f64 (*.f64 (/.f64 D l) D) (*.f64 M (*.f64 M h)))): 0 points increase in error, 0 points decrease in error
      (*.f64 (/.f64 1/4 (Rewrite<= unpow2_binary64 (pow.f64 d 2))) (*.f64 (*.f64 (/.f64 D l) D) (*.f64 M (*.f64 M h)))): 0 points increase in error, 0 points decrease in error
      (*.f64 (/.f64 1/4 (pow.f64 d 2)) (*.f64 (Rewrite<= associate-/r/_binary64 (/.f64 D (/.f64 l D))) (*.f64 M (*.f64 M h)))): 3 points increase in error, 3 points decrease in error
      (*.f64 (/.f64 1/4 (pow.f64 d 2)) (*.f64 (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 D D) l)) (*.f64 M (*.f64 M h)))): 13 points increase in error, 0 points decrease in error
      (*.f64 (/.f64 1/4 (pow.f64 d 2)) (*.f64 (/.f64 (Rewrite<= unpow2_binary64 (pow.f64 D 2)) l) (*.f64 M (*.f64 M h)))): 0 points increase in error, 0 points decrease in error
      (*.f64 (/.f64 1/4 (pow.f64 d 2)) (*.f64 (/.f64 (pow.f64 D 2) l) (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 M M) h)))): 10 points increase in error, 4 points decrease in error
      (*.f64 (/.f64 1/4 (pow.f64 d 2)) (*.f64 (/.f64 (pow.f64 D 2) l) (*.f64 (Rewrite<= unpow2_binary64 (pow.f64 M 2)) h))): 0 points increase in error, 0 points decrease in error
      (*.f64 (/.f64 1/4 (pow.f64 d 2)) (*.f64 (/.f64 (pow.f64 D 2) l) (Rewrite<= *-commutative_binary64 (*.f64 h (pow.f64 M 2))))): 0 points increase in error, 0 points decrease in error
      (*.f64 (/.f64 1/4 (pow.f64 d 2)) (Rewrite<= associate-/r/_binary64 (/.f64 (pow.f64 D 2) (/.f64 l (*.f64 h (pow.f64 M 2)))))): 5 points increase in error, 12 points decrease in error
      (*.f64 (/.f64 1/4 (pow.f64 d 2)) (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 (pow.f64 D 2) (*.f64 h (pow.f64 M 2))) l))): 6 points increase in error, 6 points decrease in error
      (Rewrite<= times-frac_binary64 (/.f64 (*.f64 1/4 (*.f64 (pow.f64 D 2) (*.f64 h (pow.f64 M 2)))) (*.f64 (pow.f64 d 2) l))): 9 points increase in error, 5 points decrease in error
      (/.f64 (*.f64 1/4 (*.f64 (pow.f64 D 2) (Rewrite=> *-commutative_binary64 (*.f64 (pow.f64 M 2) h)))) (*.f64 (pow.f64 d 2) l)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-*r/_binary64 (*.f64 1/4 (/.f64 (*.f64 (pow.f64 D 2) (*.f64 (pow.f64 M 2) h)) (*.f64 (pow.f64 d 2) l)))): 0 points increase in error, 0 points decrease in error
    5. Applied egg-rr58.2

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

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

    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.9999999999999998e-13 < (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 2 d)) 2) (/.f64 h l))

    1. Initial program 60.2

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

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

      \[\leadsto \color{blue}{w0} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification8.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(\frac{0.5}{d} \cdot \sqrt{\frac{D \cdot D}{\ell} \cdot \left(\left(M \cdot h\right) \cdot \left(-M\right)\right)}\right)\\ \mathbf{elif}\;{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell} \leq 10^{-12}:\\ \;\;\;\;w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}}\\ \mathbf{else}:\\ \;\;\;\;w0\\ \end{array} \]

Alternatives

Alternative 1
Error9.7
Cost14084
\[\begin{array}{l} \mathbf{if}\;\frac{h}{\ell} \leq -1 \cdot 10^{-188}:\\ \;\;\;\;w0 \cdot \sqrt{1 - \frac{h \cdot {\left(\frac{0.5}{\frac{\frac{d}{D}}{M}}\right)}^{2}}{\ell}}\\ \mathbf{else}:\\ \;\;\;\;w0\\ \end{array} \]
Alternative 2
Error14.6
Cost8008
\[\begin{array}{l} \mathbf{if}\;M \leq -1.9 \cdot 10^{+240}:\\ \;\;\;\;w0\\ \mathbf{elif}\;M \leq -8.5 \cdot 10^{+87}:\\ \;\;\;\;w0 \cdot \sqrt{1 + \left(\frac{h}{\ell} \cdot \frac{M \cdot \left(M \cdot \left(D \cdot D\right)\right)}{d \cdot d}\right) \cdot -0.25}\\ \mathbf{else}:\\ \;\;\;\;w0\\ \end{array} \]
Alternative 3
Error13.5
Cost64
\[w0 \]

Error

Reproduce

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