Average Error: 59.4 → 26.5
Time: 14.0s
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} t_0 := \mathsf{fma}\left(0.25, \left(\frac{D}{d} \cdot \frac{D}{d}\right) \cdot \left(M \cdot \left(M \cdot h\right)\right), 0\right)\\ \mathbf{if}\;c0 \leq 3.3 \cdot 10^{-150}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c0 \leq 1.6 \cdot 10^{+54}:\\ \;\;\;\;\mathsf{fma}\left(0.25, \left(D \cdot D\right) \cdot \left(\frac{M}{\frac{d}{M}} \cdot \frac{h}{d}\right), \frac{0}{w} \cdot \left(c0 \cdot c0\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \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
 (let* ((t_0 (fma 0.25 (* (* (/ D d) (/ D d)) (* M (* M h))) 0.0)))
   (if (<= c0 3.3e-150)
     t_0
     (if (<= c0 1.6e+54)
       (fma 0.25 (* (* D D) (* (/ M (/ d M)) (/ h d))) (* (/ 0.0 w) (* c0 c0)))
       t_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 t_0 = fma(0.25, (((D / d) * (D / d)) * (M * (M * h))), 0.0);
	double tmp;
	if (c0 <= 3.3e-150) {
		tmp = t_0;
	} else if (c0 <= 1.6e+54) {
		tmp = fma(0.25, ((D * D) * ((M / (d / M)) * (h / d))), ((0.0 / w) * (c0 * c0)));
	} else {
		tmp = t_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)
	t_0 = fma(0.25, Float64(Float64(Float64(D / d) * Float64(D / d)) * Float64(M * Float64(M * h))), 0.0)
	tmp = 0.0
	if (c0 <= 3.3e-150)
		tmp = t_0;
	elseif (c0 <= 1.6e+54)
		tmp = fma(0.25, Float64(Float64(D * D) * Float64(Float64(M / Float64(d / M)) * Float64(h / d))), Float64(Float64(0.0 / w) * Float64(c0 * c0)));
	else
		tmp = t_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_] := Block[{t$95$0 = N[(0.25 * N[(N[(N[(D / d), $MachinePrecision] * N[(D / d), $MachinePrecision]), $MachinePrecision] * N[(M * N[(M * h), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + 0.0), $MachinePrecision]}, If[LessEqual[c0, 3.3e-150], t$95$0, If[LessEqual[c0, 1.6e+54], N[(0.25 * N[(N[(D * D), $MachinePrecision] * N[(N[(M / N[(d / M), $MachinePrecision]), $MachinePrecision] * N[(h / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(0.0 / w), $MachinePrecision] * N[(c0 * c0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$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)
\begin{array}{l}
t_0 := \mathsf{fma}\left(0.25, \left(\frac{D}{d} \cdot \frac{D}{d}\right) \cdot \left(M \cdot \left(M \cdot h\right)\right), 0\right)\\
\mathbf{if}\;c0 \leq 3.3 \cdot 10^{-150}:\\
\;\;\;\;t_0\\

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

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}

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

Derivation

  1. Split input into 2 regimes
  2. if c0 < 3.3000000000000002e-150 or 1.6e54 < c0

    1. Initial program 59.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 60.9

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

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

      \[\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) \]

    if 3.3000000000000002e-150 < c0 < 1.6e54

    1. Initial program 57.2

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

      \[\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. Simplified27.5

      \[\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 D around 0 36.6

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

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

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

Reproduce

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