Average Error: 14.6 → 9.5
Time: 17.8s
Precision: binary64
\[[M, D]=\mathsf{sort}([M, D])\]
\[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}}\]
\[\begin{array}{l} \mathbf{if}\;\frac{M \cdot D}{2 \cdot d} \leq -1.3044993591889993 \cdot 10^{+298}:\\ \;\;\;\;w0 \cdot \left(\sqrt{\left(\frac{h}{\ell} \cdot {\left(\frac{D}{d}\right)}^{2}\right) \cdot -0.25} \cdot \left(-M\right)\right)\\ \mathbf{elif}\;\frac{M \cdot D}{2 \cdot d} \leq -5.623917267795416 \cdot 10^{-59}:\\ \;\;\;\;w0 \cdot \sqrt{1 - \frac{M \cdot D}{2 \cdot d} \cdot \left(\frac{M \cdot D}{2 \cdot d} \cdot \frac{h}{\ell}\right)}\\ \mathbf{elif}\;\frac{M \cdot D}{2 \cdot d} \leq 9.038932741577317 \cdot 10^{+85}:\\ \;\;\;\;w0 \cdot \sqrt{1 - \frac{\left(\frac{D}{d} \cdot \frac{M}{2}\right) \cdot \left(h \cdot \left(\frac{D}{d} \cdot \frac{M}{2}\right)\right)}{\ell}}\\ \mathbf{else}:\\ \;\;\;\;w0 \cdot \left(\sqrt{\left(\frac{h}{\ell} \cdot {\left(\frac{D}{d}\right)}^{2}\right) \cdot -0.25} \cdot \left(-M\right)\right)\\ \end{array}\]
w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}}
\begin{array}{l}
\mathbf{if}\;\frac{M \cdot D}{2 \cdot d} \leq -1.3044993591889993 \cdot 10^{+298}:\\
\;\;\;\;w0 \cdot \left(\sqrt{\left(\frac{h}{\ell} \cdot {\left(\frac{D}{d}\right)}^{2}\right) \cdot -0.25} \cdot \left(-M\right)\right)\\

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

\mathbf{elif}\;\frac{M \cdot D}{2 \cdot d} \leq 9.038932741577317 \cdot 10^{+85}:\\
\;\;\;\;w0 \cdot \sqrt{1 - \frac{\left(\frac{D}{d} \cdot \frac{M}{2}\right) \cdot \left(h \cdot \left(\frac{D}{d} \cdot \frac{M}{2}\right)\right)}{\ell}}\\

\mathbf{else}:\\
\;\;\;\;w0 \cdot \left(\sqrt{\left(\frac{h}{\ell} \cdot {\left(\frac{D}{d}\right)}^{2}\right) \cdot -0.25} \cdot \left(-M\right)\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
 (if (<= (/ (* M D) (* 2.0 d)) -1.3044993591889993e+298)
   (* w0 (* (sqrt (* (* (/ h l) (pow (/ D d) 2.0)) -0.25)) (- M)))
   (if (<= (/ (* M D) (* 2.0 d)) -5.623917267795416e-59)
     (*
      w0
      (sqrt
       (- 1.0 (* (/ (* M D) (* 2.0 d)) (* (/ (* M D) (* 2.0 d)) (/ h l))))))
     (if (<= (/ (* M D) (* 2.0 d)) 9.038932741577317e+85)
       (*
        w0
        (sqrt
         (- 1.0 (/ (* (* (/ D d) (/ M 2.0)) (* h (* (/ D d) (/ M 2.0)))) l))))
       (* w0 (* (sqrt (* (* (/ h l) (pow (/ D d) 2.0)) -0.25)) (- M)))))))
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 tmp;
	if (((M * D) / (2.0 * d)) <= -1.3044993591889993e+298) {
		tmp = w0 * (sqrt(((h / l) * pow((D / d), 2.0)) * -0.25) * -M);
	} else if (((M * D) / (2.0 * d)) <= -5.623917267795416e-59) {
		tmp = w0 * sqrt(1.0 - (((M * D) / (2.0 * d)) * (((M * D) / (2.0 * d)) * (h / l))));
	} else if (((M * D) / (2.0 * d)) <= 9.038932741577317e+85) {
		tmp = w0 * sqrt(1.0 - ((((D / d) * (M / 2.0)) * (h * ((D / d) * (M / 2.0)))) / l));
	} else {
		tmp = w0 * (sqrt(((h / l) * pow((D / d), 2.0)) * -0.25) * -M);
	}
	return tmp;
}

Error

Bits error versus w0

Bits error versus M

Bits error versus D

Bits error versus h

Bits error versus l

Bits error versus d

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 3 regimes
  2. if (/.f64 (*.f64 M D) (*.f64 2 d)) < -1.30449935918899926e298 or 9.03893274157731697e85 < (/.f64 (*.f64 M D) (*.f64 2 d))

    1. Initial program 54.0

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

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

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

    if -1.30449935918899926e298 < (/.f64 (*.f64 M D) (*.f64 2 d)) < -5.62391726779541599e-59

    1. Initial program 20.4

      \[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}}\]
    2. Using strategy rm
    3. Applied unpow2_binary64_116620.4

      \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\left(\frac{M \cdot D}{2 \cdot d} \cdot \frac{M \cdot D}{2 \cdot d}\right)} \cdot \frac{h}{\ell}}\]
    4. Applied associate-*l*_binary64_104214.8

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

    if -5.62391726779541599e-59 < (/.f64 (*.f64 M D) (*.f64 2 d)) < 9.03893274157731697e85

    1. Initial program 6.5

      \[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}}\]
    2. Using strategy rm
    3. Applied associate-*r/_binary64_10431.5

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

      \[\leadsto w0 \cdot \sqrt{1 - \frac{\color{blue}{h \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}}}{\ell}}\]
    5. Using strategy rm
    6. Applied times-frac_binary64_11071.6

      \[\leadsto w0 \cdot \sqrt{1 - \frac{h \cdot {\color{blue}{\left(\frac{M}{2} \cdot \frac{D}{d}\right)}}^{2}}{\ell}}\]
    7. Using strategy rm
    8. Applied unpow2_binary64_11661.6

      \[\leadsto w0 \cdot \sqrt{1 - \frac{h \cdot \color{blue}{\left(\left(\frac{M}{2} \cdot \frac{D}{d}\right) \cdot \left(\frac{M}{2} \cdot \frac{D}{d}\right)\right)}}{\ell}}\]
    9. Applied associate-*r*_binary64_10411.2

      \[\leadsto w0 \cdot \sqrt{1 - \frac{\color{blue}{\left(h \cdot \left(\frac{M}{2} \cdot \frac{D}{d}\right)\right) \cdot \left(\frac{M}{2} \cdot \frac{D}{d}\right)}}{\ell}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification9.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{M \cdot D}{2 \cdot d} \leq -1.3044993591889993 \cdot 10^{+298}:\\ \;\;\;\;w0 \cdot \left(\sqrt{\left(\frac{h}{\ell} \cdot {\left(\frac{D}{d}\right)}^{2}\right) \cdot -0.25} \cdot \left(-M\right)\right)\\ \mathbf{elif}\;\frac{M \cdot D}{2 \cdot d} \leq -5.623917267795416 \cdot 10^{-59}:\\ \;\;\;\;w0 \cdot \sqrt{1 - \frac{M \cdot D}{2 \cdot d} \cdot \left(\frac{M \cdot D}{2 \cdot d} \cdot \frac{h}{\ell}\right)}\\ \mathbf{elif}\;\frac{M \cdot D}{2 \cdot d} \leq 9.038932741577317 \cdot 10^{+85}:\\ \;\;\;\;w0 \cdot \sqrt{1 - \frac{\left(\frac{D}{d} \cdot \frac{M}{2}\right) \cdot \left(h \cdot \left(\frac{D}{d} \cdot \frac{M}{2}\right)\right)}{\ell}}\\ \mathbf{else}:\\ \;\;\;\;w0 \cdot \left(\sqrt{\left(\frac{h}{\ell} \cdot {\left(\frac{D}{d}\right)}^{2}\right) \cdot -0.25} \cdot \left(-M\right)\right)\\ \end{array}\]

Reproduce

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