Average Error: 59.6 → 18.0
Time: 15.8s
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 2.35 \cdot 10^{-307}:\\ \;\;\;\;\mathsf{fma}\left(0.25, h \cdot {\left(D \cdot \frac{M}{d}\right)}^{2}, 0\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(0.25, {\left(\frac{D \cdot M}{d} \cdot \sqrt{h}\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 2.35e-307)
   (fma 0.25 (* h (pow (* D (/ M d)) 2.0)) 0.0)
   (fma 0.25 (pow (* (/ (* D M) d) (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 <= 2.35e-307) {
		tmp = fma(0.25, (h * pow((D * (M / d)), 2.0)), 0.0);
	} else {
		tmp = fma(0.25, pow((((D * M) / d) * 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 <= 2.35e-307)
		tmp = fma(0.25, Float64(h * (Float64(D * Float64(M / d)) ^ 2.0)), 0.0);
	else
		tmp = fma(0.25, (Float64(Float64(Float64(D * M) / d) * 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, 2.35e-307], N[(0.25 * N[(h * N[Power[N[(D * N[(M / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] + 0.0), $MachinePrecision], N[(0.25 * N[Power[N[(N[(N[(D * M), $MachinePrecision] / d), $MachinePrecision] * N[Sqrt[h], $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 2.35 \cdot 10^{-307}:\\
\;\;\;\;\mathsf{fma}\left(0.25, h \cdot {\left(D \cdot \frac{M}{d}\right)}^{2}, 0\right)\\

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


\end{array}

Error

Derivation

  1. Split input into 2 regimes
  2. if h < 2.34999999999999984e-307

    1. Initial program 59.6

      \[\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. Simplified28.2

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

      \[\leadsto \mathsf{fma}\left(0.25, \color{blue}{{\left(h \cdot {\left(M \cdot \frac{D}{d}\right)}^{2}\right)}^{1}}, 0\right) \]
    5. Taylor expanded in M around 0 19.2

      \[\leadsto \mathsf{fma}\left(0.25, {\left(h \cdot {\color{blue}{\left(\frac{D \cdot M}{d}\right)}}^{2}\right)}^{1}, 0\right) \]
    6. Simplified19.2

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

    if 2.34999999999999984e-307 < h

    1. Initial program 59.6

      \[\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.6

      \[\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. Simplified28.2

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

      \[\leadsto \mathsf{fma}\left(0.25, \color{blue}{{\left(h \cdot {\left(M \cdot \frac{D}{d}\right)}^{2}\right)}^{1}}, 0\right) \]
    5. Taylor expanded in M around 0 19.7

      \[\leadsto \mathsf{fma}\left(0.25, {\left(h \cdot {\color{blue}{\left(\frac{D \cdot M}{d}\right)}}^{2}\right)}^{1}, 0\right) \]
    6. Simplified19.5

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

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

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

Reproduce

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