Average Error: 59.5 → 18.1
Time: 14.4s
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}\;M \cdot M \leq 2 \cdot 10^{-268}:\\ \;\;\;\;\mathsf{fma}\left(0.25, h \cdot {\left(\frac{M \cdot D}{d}\right)}^{2}, 0\right)\\ \mathbf{elif}\;M \cdot M \leq 10^{+177}:\\ \;\;\;\;\mathsf{fma}\left(0.25, \frac{\left(M \cdot M\right) \cdot \left(h \cdot \frac{D}{d}\right)}{\frac{d}{D}}, 0\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(0.25, h \cdot {\left(D \cdot \frac{M}{d}\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 (<= (* M M) 2e-268)
   (fma 0.25 (* h (pow (/ (* M D) d) 2.0)) 0.0)
   (if (<= (* M M) 1e+177)
     (fma 0.25 (/ (* (* M M) (* h (/ D d))) (/ d D)) 0.0)
     (fma 0.25 (* h (pow (* D (/ M d)) 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 ((M * M) <= 2e-268) {
		tmp = fma(0.25, (h * pow(((M * D) / d), 2.0)), 0.0);
	} else if ((M * M) <= 1e+177) {
		tmp = fma(0.25, (((M * M) * (h * (D / d))) / (d / D)), 0.0);
	} else {
		tmp = fma(0.25, (h * pow((D * (M / d)), 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 (Float64(M * M) <= 2e-268)
		tmp = fma(0.25, Float64(h * (Float64(Float64(M * D) / d) ^ 2.0)), 0.0);
	elseif (Float64(M * M) <= 1e+177)
		tmp = fma(0.25, Float64(Float64(Float64(M * M) * Float64(h * Float64(D / d))) / Float64(d / D)), 0.0);
	else
		tmp = fma(0.25, Float64(h * (Float64(D * Float64(M / d)) ^ 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[N[(M * M), $MachinePrecision], 2e-268], N[(0.25 * N[(h * N[Power[N[(N[(M * D), $MachinePrecision] / d), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] + 0.0), $MachinePrecision], If[LessEqual[N[(M * M), $MachinePrecision], 1e+177], N[(0.25 * N[(N[(N[(M * M), $MachinePrecision] * N[(h * N[(D / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(d / D), $MachinePrecision]), $MachinePrecision] + 0.0), $MachinePrecision], N[(0.25 * N[(h * N[Power[N[(D * N[(M / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $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}\;M \cdot M \leq 2 \cdot 10^{-268}:\\
\;\;\;\;\mathsf{fma}\left(0.25, h \cdot {\left(\frac{M \cdot D}{d}\right)}^{2}, 0\right)\\

\mathbf{elif}\;M \cdot M \leq 10^{+177}:\\
\;\;\;\;\mathsf{fma}\left(0.25, \frac{\left(M \cdot M\right) \cdot \left(h \cdot \frac{D}{d}\right)}{\frac{d}{D}}, 0\right)\\

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


\end{array}

Error

Derivation

  1. Split input into 3 regimes
  2. if (*.f64 M M) < 1.99999999999999992e-268

    1. Initial program 55.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 58.5

      \[\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. Simplified22.9

      \[\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(\frac{D}{d} \cdot M\right)}^{2}\right)}^{1}}, 0\right) \]
    5. Taylor expanded in D around 0 18.9

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

    if 1.99999999999999992e-268 < (*.f64 M M) < 1e177

    1. Initial program 60.9

      \[\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. Simplified21.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-rr15.7

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

    if 1e177 < (*.f64 M M)

    1. Initial program 63.8

      \[\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 63.5

      \[\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. Simplified52.4

      \[\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-rr22.0

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

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

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

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

Reproduce

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