Average Error: 59.6 → 24.8
Time: 2.6min
Precision: binary64
Cost: 1858
\[\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right)\]
\[\begin{array}{l} \mathbf{if}\;M \cdot M \leq 0:\\ \;\;\;\;0\\ \mathbf{elif}\;M \cdot M \leq 7.480441789786484 \cdot 10^{+257}:\\ \;\;\;\;\frac{\left(M \cdot M\right) \cdot \frac{D \cdot \left(D \cdot h\right)}{d}}{d} \cdot 0.25\\ \mathbf{else}:\\ \;\;\;\;0.25 \cdot \left(\frac{M \cdot \left(h \cdot \left(D \cdot D\right)\right)}{d} \cdot \frac{M}{d}\right)\\ \end{array}\]
\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right)
\begin{array}{l}
\mathbf{if}\;M \cdot M \leq 0:\\
\;\;\;\;0\\

\mathbf{elif}\;M \cdot M \leq 7.480441789786484 \cdot 10^{+257}:\\
\;\;\;\;\frac{\left(M \cdot M\right) \cdot \frac{D \cdot \left(D \cdot h\right)}{d}}{d} \cdot 0.25\\

\mathbf{else}:\\
\;\;\;\;0.25 \cdot \left(\frac{M \cdot \left(h \cdot \left(D \cdot D\right)\right)}{d} \cdot \frac{M}{d}\right)\\

\end{array}
(FPCore (c0 w h D d M)
 :precision binary64
 (*
  (/ c0 (* 2.0 w))
  (+
   (/ (* c0 (* d d)) (* (* w h) (* D D)))
   (sqrt
    (-
     (*
      (/ (* c0 (* d d)) (* (* w h) (* D D)))
      (/ (* c0 (* d d)) (* (* w h) (* D D))))
     (* M M))))))
(FPCore (c0 w h D d M)
 :precision binary64
 (if (<= (* M M) 0.0)
   0.0
   (if (<= (* M M) 7.480441789786484e+257)
     (* (/ (* (* M M) (/ (* D (* D h)) d)) d) 0.25)
     (* 0.25 (* (/ (* M (* h (* D D))) d) (/ M d))))))
double code(double c0, double w, double h, double D, double d, double M) {
	return (c0 / (2.0 * w)) * (((c0 * (d * d)) / ((w * h) * (D * D))) + sqrt((((c0 * (d * d)) / ((w * h) * (D * D))) * ((c0 * (d * d)) / ((w * h) * (D * D)))) - (M * M)));
}
double code(double c0, double w, double h, double D, double d, double M) {
	double tmp;
	if ((M * M) <= 0.0) {
		tmp = 0.0;
	} else if ((M * M) <= 7.480441789786484e+257) {
		tmp = (((M * M) * ((D * (D * h)) / d)) / d) * 0.25;
	} else {
		tmp = 0.25 * (((M * (h * (D * D))) / d) * (M / d));
	}
	return tmp;
}

Error

Bits error versus c0

Bits error versus w

Bits error versus h

Bits error versus D

Bits error versus d

Bits error versus M

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Alternatives

Alternative 1
Error25.1
Cost1858
\[\begin{array}{l} \mathbf{if}\;M \cdot M \leq 1.225209173605404 \cdot 10^{-264}:\\ \;\;\;\;0\\ \mathbf{elif}\;M \cdot M \leq 9.141073607233573 \cdot 10^{+244}:\\ \;\;\;\;0.25 \cdot \left(\frac{D \cdot \left(D \cdot h\right)}{d} \cdot \frac{M \cdot M}{d}\right)\\ \mathbf{else}:\\ \;\;\;\;0.25 \cdot \left(\frac{M \cdot \left(h \cdot \left(D \cdot D\right)\right)}{d} \cdot \frac{M}{d}\right)\\ \end{array}\]
Alternative 2
Error26.0
Cost1858
\[\begin{array}{l} \mathbf{if}\;M \cdot M \leq 1.5885172305768867 \cdot 10^{-263}:\\ \;\;\;\;0\\ \mathbf{elif}\;M \cdot M \leq 1.208687526980433 \cdot 10^{+242}:\\ \;\;\;\;0.25 \cdot \frac{D \cdot \left(D \cdot h\right)}{\frac{d}{\frac{M \cdot M}{d}}}\\ \mathbf{else}:\\ \;\;\;\;0.25 \cdot \left(\frac{M \cdot \left(h \cdot \left(D \cdot D\right)\right)}{d} \cdot \frac{M}{d}\right)\\ \end{array}\]
Alternative 3
Error28.0
Cost1288
\[\begin{array}{l} \mathbf{if}\;M \leq -5.108797510719725 \cdot 10^{-84} \lor \neg \left(M \leq 2.814635306201088 \cdot 10^{-156}\right):\\ \;\;\;\;0.25 \cdot \frac{M \cdot \left(M \cdot \left(D \cdot \left(D \cdot h\right)\right)\right)}{d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array}\]
Alternative 4
Error28.3
Cost1858
\[\begin{array}{l} \mathbf{if}\;M \cdot M \leq 3.0844323581515815 \cdot 10^{-176}:\\ \;\;\;\;0\\ \mathbf{elif}\;M \cdot M \leq 6.138923626637231 \cdot 10^{+295}:\\ \;\;\;\;0.25 \cdot \frac{\left(M \cdot M\right) \cdot \left(D \cdot \left(D \cdot h\right)\right)}{d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;0.25 \cdot \frac{M \cdot \left(M \cdot \left(h \cdot \left(D \cdot D\right)\right)\right)}{d \cdot d}\\ \end{array}\]
Alternative 5
Error28.9
Cost1858
\[\begin{array}{l} \mathbf{if}\;d \cdot d \leq 8.3991159793012 \cdot 10^{-323}:\\ \;\;\;\;0\\ \mathbf{elif}\;d \cdot d \leq 4.0679304695238825 \cdot 10^{+251}:\\ \;\;\;\;0.25 \cdot \frac{M \cdot \left(M \cdot \left(h \cdot \left(D \cdot D\right)\right)\right)}{d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array}\]
Alternative 6
Error30.6
Cost1602
\[\begin{array}{l} \mathbf{if}\;d \leq -1.2054522051442982 \cdot 10^{+126}:\\ \;\;\;\;0\\ \mathbf{elif}\;d \leq -1.693808460392712 \cdot 10^{-162}:\\ \;\;\;\;\frac{0.25 \cdot \left(\left(M \cdot M\right) \cdot \left(h \cdot \left(D \cdot D\right)\right)\right)}{d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array}\]
Alternative 7
Error31.4
Cost64
\[0\]
Alternative 8
Error61.9
Cost64
\[1\]

Error

Derivation

  1. Split input into 3 regimes
  2. if (*.f64 M M) < 0.0

    1. Initial program 22.6

      \[0\]
    2. Simplified22.6

      \[\leadsto \color{blue}{0}\]

    if 0.0 < (*.f64 M M) < 7.4804417897864842e257

    1. Initial program 60.7

      \[\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right)\]
    2. Taylor expanded around -inf 37.3

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{\left(0.5 \cdot \frac{w \cdot \left({M}^{2} \cdot \left({D}^{2} \cdot h\right)\right)}{c0 \cdot {d}^{2}}\right)}\]
    3. Simplified37.3

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{\left(0.5 \cdot \frac{w \cdot \left(\left(M \cdot M\right) \cdot \left(h \cdot \left(D \cdot D\right)\right)\right)}{c0 \cdot \left(d \cdot d\right)}\right)}\]
    4. Taylor expanded around 0 29.4

      \[\leadsto \color{blue}{0.25 \cdot \frac{{M}^{2} \cdot \left({D}^{2} \cdot h\right)}{{d}^{2}}}\]
    5. Simplified29.4

      \[\leadsto \color{blue}{\frac{\left(h \cdot \left(D \cdot D\right)\right) \cdot \left(M \cdot M\right)}{d \cdot d} \cdot 0.25}\]
    6. Using strategy rm
    7. Applied associate-*r*_binary64_172326.8

      \[\leadsto \frac{\color{blue}{\left(\left(h \cdot D\right) \cdot D\right)} \cdot \left(M \cdot M\right)}{d \cdot d} \cdot 0.25\]
    8. Using strategy rm
    9. Applied associate-/r*_binary64_172724.2

      \[\leadsto \color{blue}{\frac{\frac{\left(\left(h \cdot D\right) \cdot D\right) \cdot \left(M \cdot M\right)}{d}}{d}} \cdot 0.25\]
    10. Simplified23.1

      \[\leadsto \frac{\color{blue}{\frac{D \cdot \left(h \cdot D\right)}{d} \cdot \left(M \cdot M\right)}}{d} \cdot 0.25\]
    11. Simplified23.1

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

    if 7.4804417897864842e257 < (*.f64 M M)

    1. Initial program 64.0

      \[\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right)\]
    2. Taylor expanded around -inf 59.9

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{\left(0.5 \cdot \frac{w \cdot \left({M}^{2} \cdot \left({D}^{2} \cdot h\right)\right)}{c0 \cdot {d}^{2}}\right)}\]
    3. Simplified59.9

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{\left(0.5 \cdot \frac{w \cdot \left(\left(M \cdot M\right) \cdot \left(h \cdot \left(D \cdot D\right)\right)\right)}{c0 \cdot \left(d \cdot d\right)}\right)}\]
    4. Taylor expanded around 0 59.2

      \[\leadsto \color{blue}{0.25 \cdot \frac{{M}^{2} \cdot \left({D}^{2} \cdot h\right)}{{d}^{2}}}\]
    5. Simplified59.2

      \[\leadsto \color{blue}{\frac{\left(h \cdot \left(D \cdot D\right)\right) \cdot \left(M \cdot M\right)}{d \cdot d} \cdot 0.25}\]
    6. Using strategy rm
    7. Applied associate-*r*_binary64_172343.5

      \[\leadsto \frac{\color{blue}{\left(\left(h \cdot \left(D \cdot D\right)\right) \cdot M\right) \cdot M}}{d \cdot d} \cdot 0.25\]
    8. Simplified43.5

      \[\leadsto \frac{\color{blue}{\left(M \cdot \left(h \cdot \left(D \cdot D\right)\right)\right)} \cdot M}{d \cdot d} \cdot 0.25\]
    9. Using strategy rm
    10. Applied times-frac_binary64_178933.9

      \[\leadsto \color{blue}{\left(\frac{M \cdot \left(h \cdot \left(D \cdot D\right)\right)}{d} \cdot \frac{M}{d}\right)} \cdot 0.25\]
    11. Simplified33.9

      \[\leadsto \color{blue}{\left(\frac{M \cdot \left(h \cdot \left(D \cdot D\right)\right)}{d} \cdot \frac{M}{d}\right) \cdot 0.25}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification24.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;M \cdot M \leq 0:\\ \;\;\;\;0\\ \mathbf{elif}\;M \cdot M \leq 7.480441789786484 \cdot 10^{+257}:\\ \;\;\;\;\frac{\left(M \cdot M\right) \cdot \frac{D \cdot \left(D \cdot h\right)}{d}}{d} \cdot 0.25\\ \mathbf{else}:\\ \;\;\;\;0.25 \cdot \left(\frac{M \cdot \left(h \cdot \left(D \cdot D\right)\right)}{d} \cdot \frac{M}{d}\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2021042 
(FPCore (c0 w h D d M)
  :name "Henrywood and Agarwal, Equation (13)"
  :precision binary64
  (* (/ c0 (* 2.0 w)) (+ (/ (* c0 (* d d)) (* (* w h) (* D D))) (sqrt (- (* (/ (* c0 (* d d)) (* (* w h) (* D D))) (/ (* c0 (* d d)) (* (* w h) (* D D)))) (* M M))))))