Average Error: 59.5 → 28.7
Time: 14.2s
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}\;d \cdot d \leq 2 \cdot 10^{-252}:\\ \;\;\;\;0\\ \mathbf{elif}\;d \cdot d \leq 5 \cdot 10^{+153}:\\ \;\;\;\;0.25 \cdot \left(D \cdot \left(\left(\frac{D}{d \cdot d} \cdot h\right) \cdot \left(M \cdot M\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;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
 (if (<= (* d d) 2e-252)
   0.0
   (if (<= (* d d) 5e+153)
     (* 0.25 (* D (* (* (/ D (* d d)) h) (* M M))))
     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 ((d * d) <= 2e-252) {
		tmp = 0.0;
	} else if ((d * d) <= 5e+153) {
		tmp = 0.25 * (D * (((D / (d * d)) * h) * (M * M)));
	} else {
		tmp = 0.0;
	}
	return tmp;
}
real(8) function code(c0, w, h, d, d_1, m)
    real(8), intent (in) :: c0
    real(8), intent (in) :: w
    real(8), intent (in) :: h
    real(8), intent (in) :: d
    real(8), intent (in) :: d_1
    real(8), intent (in) :: m
    code = (c0 / (2.0d0 * w)) * (((c0 * (d_1 * d_1)) / ((w * h) * (d * d))) + sqrt(((((c0 * (d_1 * d_1)) / ((w * h) * (d * d))) * ((c0 * (d_1 * d_1)) / ((w * h) * (d * d)))) - (m * m))))
end function
real(8) function code(c0, w, h, d, d_1, m)
    real(8), intent (in) :: c0
    real(8), intent (in) :: w
    real(8), intent (in) :: h
    real(8), intent (in) :: d
    real(8), intent (in) :: d_1
    real(8), intent (in) :: m
    real(8) :: tmp
    if ((d_1 * d_1) <= 2d-252) then
        tmp = 0.0d0
    else if ((d_1 * d_1) <= 5d+153) then
        tmp = 0.25d0 * (d * (((d / (d_1 * d_1)) * h) * (m * m)))
    else
        tmp = 0.0d0
    end if
    code = tmp
end function
public static 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))) + Math.sqrt(((((c0 * (d * d)) / ((w * h) * (D * D))) * ((c0 * (d * d)) / ((w * h) * (D * D)))) - (M * M))));
}
public static double code(double c0, double w, double h, double D, double d, double M) {
	double tmp;
	if ((d * d) <= 2e-252) {
		tmp = 0.0;
	} else if ((d * d) <= 5e+153) {
		tmp = 0.25 * (D * (((D / (d * d)) * h) * (M * M)));
	} else {
		tmp = 0.0;
	}
	return tmp;
}
def code(c0, w, h, D, d, M):
	return (c0 / (2.0 * w)) * (((c0 * (d * d)) / ((w * h) * (D * D))) + math.sqrt(((((c0 * (d * d)) / ((w * h) * (D * D))) * ((c0 * (d * d)) / ((w * h) * (D * D)))) - (M * M))))
def code(c0, w, h, D, d, M):
	tmp = 0
	if (d * d) <= 2e-252:
		tmp = 0.0
	elif (d * d) <= 5e+153:
		tmp = 0.25 * (D * (((D / (d * d)) * h) * (M * M)))
	else:
		tmp = 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(d * d) <= 2e-252)
		tmp = 0.0;
	elseif (Float64(d * d) <= 5e+153)
		tmp = Float64(0.25 * Float64(D * Float64(Float64(Float64(D / Float64(d * d)) * h) * Float64(M * M))));
	else
		tmp = 0.0;
	end
	return tmp
end
function tmp = code(c0, w, h, D, d, M)
	tmp = (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))));
end
function tmp_2 = code(c0, w, h, D, d, M)
	tmp = 0.0;
	if ((d * d) <= 2e-252)
		tmp = 0.0;
	elseif ((d * d) <= 5e+153)
		tmp = 0.25 * (D * (((D / (d * d)) * h) * (M * M)));
	else
		tmp = 0.0;
	end
	tmp_2 = 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[(d * d), $MachinePrecision], 2e-252], 0.0, If[LessEqual[N[(d * d), $MachinePrecision], 5e+153], N[(0.25 * N[(D * N[(N[(N[(D / N[(d * d), $MachinePrecision]), $MachinePrecision] * h), $MachinePrecision] * N[(M * M), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.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}
\mathbf{if}\;d \cdot d \leq 2 \cdot 10^{-252}:\\
\;\;\;\;0\\

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

\mathbf{else}:\\
\;\;\;\;0\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 2 regimes
  2. if (*.f64 d d) < 1.99999999999999989e-252 or 5.00000000000000018e153 < (*.f64 d d)

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

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{\left(-1 \cdot \left(\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\right)\right)} \]
    3. Simplified33.7

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{0} \]
    4. Taylor expanded in c0 around 0 29.8

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

    if 1.99999999999999989e-252 < (*.f64 d d) < 5.00000000000000018e153

    1. Initial program 54.3

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

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{\left(0.5 \cdot \frac{{D}^{2} \cdot \left(w \cdot \left({M}^{2} \cdot h\right)\right)}{{d}^{2} \cdot c0} + -1 \cdot \left(\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\right)\right)} \]
    3. Simplified39.0

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

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

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

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

Reproduce

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