Average Error: 14.5 → 8.8
Time: 28.3s
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} t_0 := \frac{M \cdot D}{2 \cdot d}\\ t_1 := {t_0}^{2}\\ t_2 := w0 \cdot \sqrt{1 - t_1 \cdot \frac{h}{\ell}}\\ \mathbf{if}\;t_2 \leq -\infty:\\ \;\;\;\;w0 \cdot \left(D \cdot \sqrt{\left(\frac{h}{\ell} \cdot {\left(\frac{M}{d}\right)}^{2}\right) \cdot -0.25}\right)\\ \mathbf{elif}\;t_2 \leq 7.412898074004929 \cdot 10^{+305}:\\ \;\;\;\;w0 \cdot \sqrt{1 - \frac{t_1}{\frac{\ell}{h}}}\\ \mathbf{elif}\;t_2 \leq \infty:\\ \;\;\;\;-\sqrt{-0.25 \cdot \frac{h \cdot {D}^{2}}{\ell \cdot {d}^{2}}} \cdot \left(w0 \cdot M\right)\\ \mathbf{else}:\\ \;\;\;\;w0 \cdot \sqrt{1 - \frac{t_0}{\sqrt[3]{\ell} \cdot \sqrt[3]{\ell}} \cdot \frac{t_0 \cdot h}{\sqrt[3]{\ell}}}\\ \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 := \frac{M \cdot D}{2 \cdot d}\\
t_1 := {t_0}^{2}\\
t_2 := w0 \cdot \sqrt{1 - t_1 \cdot \frac{h}{\ell}}\\
\mathbf{if}\;t_2 \leq -\infty:\\
\;\;\;\;w0 \cdot \left(D \cdot \sqrt{\left(\frac{h}{\ell} \cdot {\left(\frac{M}{d}\right)}^{2}\right) \cdot -0.25}\right)\\

\mathbf{elif}\;t_2 \leq 7.412898074004929 \cdot 10^{+305}:\\
\;\;\;\;w0 \cdot \sqrt{1 - \frac{t_1}{\frac{\ell}{h}}}\\

\mathbf{elif}\;t_2 \leq \infty:\\
\;\;\;\;-\sqrt{-0.25 \cdot \frac{h \cdot {D}^{2}}{\ell \cdot {d}^{2}}} \cdot \left(w0 \cdot M\right)\\

\mathbf{else}:\\
\;\;\;\;w0 \cdot \sqrt{1 - \frac{t_0}{\sqrt[3]{\ell} \cdot \sqrt[3]{\ell}} \cdot \frac{t_0 \cdot h}{\sqrt[3]{\ell}}}\\


\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 (/ (* M D) (* 2.0 d)))
        (t_1 (pow t_0 2.0))
        (t_2 (* w0 (sqrt (- 1.0 (* t_1 (/ h l)))))))
   (if (<= t_2 (- INFINITY))
     (* w0 (* D (sqrt (* (* (/ h l) (pow (/ M d) 2.0)) -0.25))))
     (if (<= t_2 7.412898074004929e+305)
       (* w0 (sqrt (- 1.0 (/ t_1 (/ l h)))))
       (if (<= t_2 INFINITY)
         (-
          (*
           (sqrt (* -0.25 (/ (* h (pow D 2.0)) (* l (pow d 2.0)))))
           (* w0 M)))
         (*
          w0
          (sqrt
           (-
            1.0
            (* (/ t_0 (* (cbrt l) (cbrt l))) (/ (* t_0 h) (cbrt 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 = (M * D) / (2.0 * d);
	double t_1 = pow(t_0, 2.0);
	double t_2 = w0 * sqrt(1.0 - (t_1 * (h / l)));
	double tmp;
	if (t_2 <= -((double) INFINITY)) {
		tmp = w0 * (D * sqrt(((h / l) * pow((M / d), 2.0)) * -0.25));
	} else if (t_2 <= 7.412898074004929e+305) {
		tmp = w0 * sqrt(1.0 - (t_1 / (l / h)));
	} else if (t_2 <= ((double) INFINITY)) {
		tmp = -(sqrt(-0.25 * ((h * pow(D, 2.0)) / (l * pow(d, 2.0)))) * (w0 * M));
	} else {
		tmp = w0 * sqrt(1.0 - ((t_0 / (cbrt(l) * cbrt(l))) * ((t_0 * h) / cbrt(l))));
	}
	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 4 regimes
  2. if (*.f64 w0 (sqrt.f64 (-.f64 1 (*.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 associate-*r/_binary6459.5

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

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

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

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

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

    if -inf.0 < (*.f64 w0 (sqrt.f64 (-.f64 1 (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 2 d)) 2) (/.f64 h l))))) < 7.4128980740049289e305

    1. Initial program 0.1

      \[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]
    2. Applied associate-*r/_binary641.0

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

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

    if 7.4128980740049289e305 < (*.f64 w0 (sqrt.f64 (-.f64 1 (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 2 d)) 2) (/.f64 h l))))) < +inf.0

    1. Initial program 62.4

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

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

    if +inf.0 < (*.f64 w0 (sqrt.f64 (-.f64 1 (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 2 d)) 2) (/.f64 h l)))))

    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 associate-*r/_binary6427.6

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

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

      \[\leadsto w0 \cdot \sqrt{1 - \frac{\color{blue}{\frac{M \cdot D}{2 \cdot d} \cdot \left(\frac{M \cdot D}{2 \cdot d} \cdot h\right)}}{\ell}} \]
    5. Applied add-cube-cbrt_binary6416.0

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

      \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\frac{\frac{M \cdot D}{2 \cdot d}}{\sqrt[3]{\ell} \cdot \sqrt[3]{\ell}} \cdot \frac{\frac{M \cdot D}{2 \cdot d} \cdot h}{\sqrt[3]{\ell}}}} \]
    7. Simplified14.5

      \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\frac{\frac{D \cdot M}{d \cdot 2}}{\sqrt[3]{\ell} \cdot \sqrt[3]{\ell}}} \cdot \frac{\frac{M \cdot D}{2 \cdot d} \cdot h}{\sqrt[3]{\ell}}} \]
    8. Simplified14.5

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

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

Reproduce

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