Average Error: 59.7 → 20.1
Time: 13.7s
Precision: binary64
\[\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}\;h \leq 0:\\ \;\;\;\;\mathsf{fma}\left(0.25, \frac{\frac{M \cdot \left(h \cdot M\right)}{\frac{d}{D}}}{\frac{d}{D}}, 0\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(0.25, {\left(\frac{D}{d} \cdot \left(M \cdot \sqrt{h}\right)\right)}^{2}, 0\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 (<= h 0.0)
   (fma 0.25 (/ (/ (* M (* h M)) (/ d D)) (/ d D)) 0.0)
   (fma 0.25 (pow (* (/ D d) (* M (sqrt h))) 2.0) 0.0)))
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 (h <= 0.0) {
		tmp = fma(0.25, (((M * (h * M)) / (d / D)) / (d / D)), 0.0);
	} else {
		tmp = fma(0.25, pow(((D / d) * (M * sqrt(h))), 2.0), 0.0);
	}
	return tmp;
}
function code(c0, w, h, D, d, M)
	return Float64(Float64(c0 / Float64(2.0 * w)) * Float64(Float64(Float64(c0 * Float64(d * d)) / Float64(Float64(w * h) * Float64(D * D))) + sqrt(Float64(Float64(Float64(Float64(c0 * Float64(d * d)) / Float64(Float64(w * h) * Float64(D * D))) * Float64(Float64(c0 * Float64(d * d)) / Float64(Float64(w * h) * Float64(D * D)))) - Float64(M * M)))))
end
function code(c0, w, h, D, d, M)
	tmp = 0.0
	if (h <= 0.0)
		tmp = fma(0.25, Float64(Float64(Float64(M * Float64(h * M)) / Float64(d / D)) / Float64(d / D)), 0.0);
	else
		tmp = fma(0.25, (Float64(Float64(D / d) * Float64(M * sqrt(h))) ^ 2.0), 0.0);
	end
	return tmp
end
code[c0_, w_, h_, D_, d_, M_] := N[(N[(c0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision] * N[(N[(N[(c0 * N[(d * d), $MachinePrecision]), $MachinePrecision] / N[(N[(w * h), $MachinePrecision] * N[(D * D), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[Sqrt[N[(N[(N[(N[(c0 * N[(d * d), $MachinePrecision]), $MachinePrecision] / N[(N[(w * h), $MachinePrecision] * N[(D * D), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[(c0 * N[(d * d), $MachinePrecision]), $MachinePrecision] / N[(N[(w * h), $MachinePrecision] * N[(D * D), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(M * M), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[c0_, w_, h_, D_, d_, M_] := If[LessEqual[h, 0.0], N[(0.25 * N[(N[(N[(M * N[(h * M), $MachinePrecision]), $MachinePrecision] / N[(d / D), $MachinePrecision]), $MachinePrecision] / N[(d / D), $MachinePrecision]), $MachinePrecision] + 0.0), $MachinePrecision], N[(0.25 * N[Power[N[(N[(D / d), $MachinePrecision] * N[(M * N[Sqrt[h], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + 0.0), $MachinePrecision]]
\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}\;h \leq 0:\\
\;\;\;\;\mathsf{fma}\left(0.25, \frac{\frac{M \cdot \left(h \cdot M\right)}{\frac{d}{D}}}{\frac{d}{D}}, 0\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.25, {\left(\frac{D}{d} \cdot \left(M \cdot \sqrt{h}\right)\right)}^{2}, 0\right)\\


\end{array}

Error

Derivation

  1. Split input into 2 regimes
  2. if h < 0.0

    1. Initial program 59.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 in c0 around -inf 60.4

      \[\leadsto \color{blue}{-0.5 \cdot \frac{\left(\frac{{d}^{2}}{{D}^{2} \cdot \left(w \cdot h\right)} + -1 \cdot \frac{{d}^{2}}{{D}^{2} \cdot \left(w \cdot h\right)}\right) \cdot {c0}^{2}}{w} + 0.25 \cdot \frac{{D}^{2} \cdot \left({M}^{2} \cdot h\right)}{{d}^{2}}} \]
    3. Simplified36.6

      \[\leadsto \color{blue}{\mathsf{fma}\left(0.25, \left(\frac{D}{d} \cdot \frac{D}{d}\right) \cdot \left(M \cdot \left(M \cdot h\right)\right), \frac{0}{w} \cdot \left(c0 \cdot c0\right)\right)} \]
    4. Taylor expanded in w around 0 25.9

      \[\leadsto \mathsf{fma}\left(0.25, \left(\frac{D}{d} \cdot \frac{D}{d}\right) \cdot \left(M \cdot \left(M \cdot h\right)\right), \color{blue}{0}\right) \]
    5. Applied egg-rr26.0

      \[\leadsto \mathsf{fma}\left(0.25, \color{blue}{\frac{1}{\frac{d}{D} \cdot \frac{d}{D}}} \cdot \left(M \cdot \left(M \cdot h\right)\right), 0\right) \]
    6. Applied egg-rr23.4

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

    if 0.0 < h

    1. Initial program 59.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 in c0 around -inf 60.4

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(0.25, \left(\frac{D}{d} \cdot \frac{D}{d}\right) \cdot \left(M \cdot \left(M \cdot h\right)\right), \frac{0}{w} \cdot \left(c0 \cdot c0\right)\right)} \]
    4. Taylor expanded in w around 0 25.2

      \[\leadsto \mathsf{fma}\left(0.25, \left(\frac{D}{d} \cdot \frac{D}{d}\right) \cdot \left(M \cdot \left(M \cdot h\right)\right), \color{blue}{0}\right) \]
    5. Applied egg-rr16.9

      \[\leadsto \mathsf{fma}\left(0.25, \color{blue}{{\left(\frac{D}{d} \cdot \left(M \cdot \sqrt{h}\right)\right)}^{2}}, 0\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification20.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;h \leq 0:\\ \;\;\;\;\mathsf{fma}\left(0.25, \frac{\frac{M \cdot \left(h \cdot M\right)}{\frac{d}{D}}}{\frac{d}{D}}, 0\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(0.25, {\left(\frac{D}{d} \cdot \left(M \cdot \sqrt{h}\right)\right)}^{2}, 0\right)\\ \end{array} \]

Reproduce

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