Average Error: 59.7 → 19.5
Time: 20.1s
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 := \frac{d}{D \cdot M}\\ \mathbf{if}\;d \cdot d \leq 1.879591919976094 \cdot 10^{-234}:\\ \;\;\;\;0.25 \cdot {\left(\frac{1}{\frac{h}{{t_0}^{2}}}\right)}^{-1}\\ \mathbf{elif}\;d \cdot d \leq 2.199066478769789 \cdot 10^{+195}:\\ \;\;\;\;0.25 \cdot {\left(\frac{d \cdot t_0}{h \cdot \left(D \cdot M\right)}\right)}^{-1}\\ \mathbf{else}:\\ \;\;\;\;0.25 \cdot \frac{D \cdot M}{t_0 \cdot \frac{d}{h}}\\ \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 (/ d (* D M))))
   (if (<= (* d d) 1.879591919976094e-234)
     (* 0.25 (pow (/ 1.0 (/ h (pow t_0 2.0))) -1.0))
     (if (<= (* d d) 2.199066478769789e+195)
       (* 0.25 (pow (/ (* d t_0) (* h (* D M))) -1.0))
       (* 0.25 (/ (* D M) (* t_0 (/ d h))))))))
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 = d / (D * M);
	double tmp;
	if ((d * d) <= 1.879591919976094e-234) {
		tmp = 0.25 * pow((1.0 / (h / pow(t_0, 2.0))), -1.0);
	} else if ((d * d) <= 2.199066478769789e+195) {
		tmp = 0.25 * pow(((d * t_0) / (h * (D * M))), -1.0);
	} else {
		tmp = 0.25 * ((D * M) / (t_0 * (d / h)));
	}
	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) :: t_0
    real(8) :: tmp
    t_0 = d_1 / (d * m)
    if ((d_1 * d_1) <= 1.879591919976094d-234) then
        tmp = 0.25d0 * ((1.0d0 / (h / (t_0 ** 2.0d0))) ** (-1.0d0))
    else if ((d_1 * d_1) <= 2.199066478769789d+195) then
        tmp = 0.25d0 * (((d_1 * t_0) / (h * (d * m))) ** (-1.0d0))
    else
        tmp = 0.25d0 * ((d * m) / (t_0 * (d_1 / h)))
    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 t_0 = d / (D * M);
	double tmp;
	if ((d * d) <= 1.879591919976094e-234) {
		tmp = 0.25 * Math.pow((1.0 / (h / Math.pow(t_0, 2.0))), -1.0);
	} else if ((d * d) <= 2.199066478769789e+195) {
		tmp = 0.25 * Math.pow(((d * t_0) / (h * (D * M))), -1.0);
	} else {
		tmp = 0.25 * ((D * M) / (t_0 * (d / h)));
	}
	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):
	t_0 = d / (D * M)
	tmp = 0
	if (d * d) <= 1.879591919976094e-234:
		tmp = 0.25 * math.pow((1.0 / (h / math.pow(t_0, 2.0))), -1.0)
	elif (d * d) <= 2.199066478769789e+195:
		tmp = 0.25 * math.pow(((d * t_0) / (h * (D * M))), -1.0)
	else:
		tmp = 0.25 * ((D * M) / (t_0 * (d / h)))
	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 = Float64(d / Float64(D * M))
	tmp = 0.0
	if (Float64(d * d) <= 1.879591919976094e-234)
		tmp = Float64(0.25 * (Float64(1.0 / Float64(h / (t_0 ^ 2.0))) ^ -1.0));
	elseif (Float64(d * d) <= 2.199066478769789e+195)
		tmp = Float64(0.25 * (Float64(Float64(d * t_0) / Float64(h * Float64(D * M))) ^ -1.0));
	else
		tmp = Float64(0.25 * Float64(Float64(D * M) / Float64(t_0 * Float64(d / h))));
	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)
	t_0 = d / (D * M);
	tmp = 0.0;
	if ((d * d) <= 1.879591919976094e-234)
		tmp = 0.25 * ((1.0 / (h / (t_0 ^ 2.0))) ^ -1.0);
	elseif ((d * d) <= 2.199066478769789e+195)
		tmp = 0.25 * (((d * t_0) / (h * (D * M))) ^ -1.0);
	else
		tmp = 0.25 * ((D * M) / (t_0 * (d / h)));
	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_] := Block[{t$95$0 = N[(d / N[(D * M), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(d * d), $MachinePrecision], 1.879591919976094e-234], N[(0.25 * N[Power[N[(1.0 / N[(h / N[Power[t$95$0, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -1.0], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(d * d), $MachinePrecision], 2.199066478769789e+195], N[(0.25 * N[Power[N[(N[(d * t$95$0), $MachinePrecision] / N[(h * N[(D * M), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -1.0], $MachinePrecision]), $MachinePrecision], N[(0.25 * N[(N[(D * M), $MachinePrecision] / N[(t$95$0 * N[(d / h), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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}
t_0 := \frac{d}{D \cdot M}\\
\mathbf{if}\;d \cdot d \leq 1.879591919976094 \cdot 10^{-234}:\\
\;\;\;\;0.25 \cdot {\left(\frac{1}{\frac{h}{{t_0}^{2}}}\right)}^{-1}\\

\mathbf{elif}\;d \cdot d \leq 2.199066478769789 \cdot 10^{+195}:\\
\;\;\;\;0.25 \cdot {\left(\frac{d \cdot t_0}{h \cdot \left(D \cdot M\right)}\right)}^{-1}\\

\mathbf{else}:\\
\;\;\;\;0.25 \cdot \frac{D \cdot M}{t_0 \cdot \frac{d}{h}}\\


\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

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 3 regimes
  2. if (*.f64 d d) < 1.8795919199760939e-234

    1. Initial program 61.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 55.3

      \[\leadsto \color{blue}{0.25 \cdot \frac{{D}^{2} \cdot \left({M}^{2} \cdot h\right)}{{d}^{2}}} \]
    3. Applied egg-rr36.9

      \[\leadsto 0.25 \cdot \color{blue}{{\left(\frac{d}{{\left(D \cdot M\right)}^{2}} \cdot \frac{d}{h}\right)}^{-1}} \]
    4. Applied egg-rr30.2

      \[\leadsto 0.25 \cdot {\left(\color{blue}{\left(\frac{1}{D \cdot M} \cdot \frac{d}{D \cdot M}\right)} \cdot \frac{d}{h}\right)}^{-1} \]
    5. Applied egg-rr28.0

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

    if 1.8795919199760939e-234 < (*.f64 d d) < 2.19906647876978904e195

    1. Initial program 55.1

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

      \[\leadsto \color{blue}{0.25 \cdot \frac{{D}^{2} \cdot \left({M}^{2} \cdot h\right)}{{d}^{2}}} \]
    3. Applied egg-rr21.8

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

      \[\leadsto 0.25 \cdot {\left(\color{blue}{\left(\frac{1}{D \cdot M} \cdot \frac{d}{D \cdot M}\right)} \cdot \frac{d}{h}\right)}^{-1} \]
    5. Applied egg-rr17.4

      \[\leadsto 0.25 \cdot {\color{blue}{\left(\frac{\frac{d}{D \cdot M} \cdot d}{\left(D \cdot M\right) \cdot h}\right)}}^{-1} \]

    if 2.19906647876978904e195 < (*.f64 d d)

    1. Initial program 62.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 32.9

      \[\leadsto \color{blue}{0.25 \cdot \frac{{D}^{2} \cdot \left({M}^{2} \cdot h\right)}{{d}^{2}}} \]
    3. Applied egg-rr21.4

      \[\leadsto 0.25 \cdot \color{blue}{{\left(\frac{d}{{\left(D \cdot M\right)}^{2}} \cdot \frac{d}{h}\right)}^{-1}} \]
    4. Applied egg-rr18.2

      \[\leadsto 0.25 \cdot {\left(\color{blue}{\left(\frac{1}{D \cdot M} \cdot \frac{d}{D \cdot M}\right)} \cdot \frac{d}{h}\right)}^{-1} \]
    5. Applied egg-rr18.5

      \[\leadsto 0.25 \cdot \color{blue}{\frac{D \cdot M}{\frac{d}{D \cdot M} \cdot \frac{d}{h}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification19.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \cdot d \leq 1.879591919976094 \cdot 10^{-234}:\\ \;\;\;\;0.25 \cdot {\left(\frac{1}{\frac{h}{{\left(\frac{d}{D \cdot M}\right)}^{2}}}\right)}^{-1}\\ \mathbf{elif}\;d \cdot d \leq 2.199066478769789 \cdot 10^{+195}:\\ \;\;\;\;0.25 \cdot {\left(\frac{d \cdot \frac{d}{D \cdot M}}{h \cdot \left(D \cdot M\right)}\right)}^{-1}\\ \mathbf{else}:\\ \;\;\;\;0.25 \cdot \frac{D \cdot M}{\frac{d}{D \cdot M} \cdot \frac{d}{h}}\\ \end{array} \]

Reproduce

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