Average Error: 59.7 → 15.9
Time: 22.6s
Precision: binary64
Cost: 30540
\[\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{M \cdot \left(h \cdot \left(M \cdot \frac{D}{d}\right)\right)}{\frac{d}{D}} \cdot 0.25\\ t_1 := \frac{\frac{c0}{2}}{w} \cdot \left(2 \cdot \frac{c0 \cdot \frac{d}{D}}{\left(w \cdot h\right) \cdot \frac{D}{d}}\right)\\ t_2 := \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}\\ t_3 := \frac{c0}{2 \cdot w} \cdot \left(t_2 + \sqrt{t_2 \cdot t_2 - M \cdot M}\right)\\ \mathbf{if}\;t_3 \leq -1 \cdot 10^{-69}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_3 \leq 0:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_3 \leq \infty:\\ \;\;\;\;t_1\\ \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 (* (/ (* M (* h (* M (/ D d)))) (/ d D)) 0.25))
        (t_1
         (* (/ (/ c0 2.0) w) (* 2.0 (/ (* c0 (/ d D)) (* (* w h) (/ D d))))))
        (t_2 (/ (* c0 (* d d)) (* (* w h) (* D D))))
        (t_3 (* (/ c0 (* 2.0 w)) (+ t_2 (sqrt (- (* t_2 t_2) (* M M)))))))
   (if (<= t_3 -1e-69)
     t_1
     (if (<= t_3 0.0) t_0 (if (<= t_3 INFINITY) t_1 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 = ((M * (h * (M * (D / d)))) / (d / D)) * 0.25;
	double t_1 = ((c0 / 2.0) / w) * (2.0 * ((c0 * (d / D)) / ((w * h) * (D / d))));
	double t_2 = (c0 * (d * d)) / ((w * h) * (D * D));
	double t_3 = (c0 / (2.0 * w)) * (t_2 + sqrt(((t_2 * t_2) - (M * M))));
	double tmp;
	if (t_3 <= -1e-69) {
		tmp = t_1;
	} else if (t_3 <= 0.0) {
		tmp = t_0;
	} else if (t_3 <= ((double) INFINITY)) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
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 = ((M * (h * (M * (D / d)))) / (d / D)) * 0.25;
	double t_1 = ((c0 / 2.0) / w) * (2.0 * ((c0 * (d / D)) / ((w * h) * (D / d))));
	double t_2 = (c0 * (d * d)) / ((w * h) * (D * D));
	double t_3 = (c0 / (2.0 * w)) * (t_2 + Math.sqrt(((t_2 * t_2) - (M * M))));
	double tmp;
	if (t_3 <= -1e-69) {
		tmp = t_1;
	} else if (t_3 <= 0.0) {
		tmp = t_0;
	} else if (t_3 <= Double.POSITIVE_INFINITY) {
		tmp = t_1;
	} else {
		tmp = t_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):
	t_0 = ((M * (h * (M * (D / d)))) / (d / D)) * 0.25
	t_1 = ((c0 / 2.0) / w) * (2.0 * ((c0 * (d / D)) / ((w * h) * (D / d))))
	t_2 = (c0 * (d * d)) / ((w * h) * (D * D))
	t_3 = (c0 / (2.0 * w)) * (t_2 + math.sqrt(((t_2 * t_2) - (M * M))))
	tmp = 0
	if t_3 <= -1e-69:
		tmp = t_1
	elif t_3 <= 0.0:
		tmp = t_0
	elif t_3 <= math.inf:
		tmp = t_1
	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 = Float64(Float64(Float64(M * Float64(h * Float64(M * Float64(D / d)))) / Float64(d / D)) * 0.25)
	t_1 = Float64(Float64(Float64(c0 / 2.0) / w) * Float64(2.0 * Float64(Float64(c0 * Float64(d / D)) / Float64(Float64(w * h) * Float64(D / d)))))
	t_2 = Float64(Float64(c0 * Float64(d * d)) / Float64(Float64(w * h) * Float64(D * D)))
	t_3 = Float64(Float64(c0 / Float64(2.0 * w)) * Float64(t_2 + sqrt(Float64(Float64(t_2 * t_2) - Float64(M * M)))))
	tmp = 0.0
	if (t_3 <= -1e-69)
		tmp = t_1;
	elseif (t_3 <= 0.0)
		tmp = t_0;
	elseif (t_3 <= Inf)
		tmp = t_1;
	else
		tmp = t_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)
	t_0 = ((M * (h * (M * (D / d)))) / (d / D)) * 0.25;
	t_1 = ((c0 / 2.0) / w) * (2.0 * ((c0 * (d / D)) / ((w * h) * (D / d))));
	t_2 = (c0 * (d * d)) / ((w * h) * (D * D));
	t_3 = (c0 / (2.0 * w)) * (t_2 + sqrt(((t_2 * t_2) - (M * M))));
	tmp = 0.0;
	if (t_3 <= -1e-69)
		tmp = t_1;
	elseif (t_3 <= 0.0)
		tmp = t_0;
	elseif (t_3 <= Inf)
		tmp = t_1;
	else
		tmp = t_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_] := Block[{t$95$0 = N[(N[(N[(M * N[(h * N[(M * N[(D / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(d / D), $MachinePrecision]), $MachinePrecision] * 0.25), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(c0 / 2.0), $MachinePrecision] / w), $MachinePrecision] * N[(2.0 * N[(N[(c0 * N[(d / D), $MachinePrecision]), $MachinePrecision] / N[(N[(w * h), $MachinePrecision] * N[(D / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(c0 * N[(d * d), $MachinePrecision]), $MachinePrecision] / N[(N[(w * h), $MachinePrecision] * N[(D * D), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(N[(c0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision] * N[(t$95$2 + N[Sqrt[N[(N[(t$95$2 * t$95$2), $MachinePrecision] - N[(M * M), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$3, -1e-69], t$95$1, If[LessEqual[t$95$3, 0.0], t$95$0, If[LessEqual[t$95$3, Infinity], t$95$1, 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 := \frac{M \cdot \left(h \cdot \left(M \cdot \frac{D}{d}\right)\right)}{\frac{d}{D}} \cdot 0.25\\
t_1 := \frac{\frac{c0}{2}}{w} \cdot \left(2 \cdot \frac{c0 \cdot \frac{d}{D}}{\left(w \cdot h\right) \cdot \frac{D}{d}}\right)\\
t_2 := \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}\\
t_3 := \frac{c0}{2 \cdot w} \cdot \left(t_2 + \sqrt{t_2 \cdot t_2 - M \cdot M}\right)\\
\mathbf{if}\;t_3 \leq -1 \cdot 10^{-69}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_3 \leq 0:\\
\;\;\;\;t_0\\

\mathbf{elif}\;t_3 \leq \infty:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;t_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 (/.f64 c0 (*.f64 2 w)) (+.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (sqrt.f64 (-.f64 (*.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D)))) (*.f64 M M))))) < -9.9999999999999996e-70 or -0.0 < (*.f64 (/.f64 c0 (*.f64 2 w)) (+.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (sqrt.f64 (-.f64 (*.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D)))) (*.f64 M M))))) < +inf.0

    1. Initial program 51.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. Simplified57.9

      \[\leadsto \color{blue}{\frac{\frac{c0}{2}}{w} \cdot \mathsf{fma}\left(d \cdot d, \frac{c0}{w \cdot \left(h \cdot \left(D \cdot D\right)\right)}, \sqrt{\left(\frac{c0}{w \cdot h} \cdot \frac{c0}{w \cdot h}\right) \cdot {\left(\frac{d}{D}\right)}^{4} - M \cdot M}\right)} \]
    3. Taylor expanded in d around inf 45.1

      \[\leadsto \frac{\frac{c0}{2}}{w} \cdot \color{blue}{\left(2 \cdot \frac{{d}^{2} \cdot c0}{{D}^{2} \cdot \left(w \cdot h\right)}\right)} \]
    4. Simplified42.8

      \[\leadsto \frac{\frac{c0}{2}}{w} \cdot \color{blue}{\left(2 \cdot \left(\frac{\frac{d}{D} \cdot \frac{d}{D}}{w \cdot h} \cdot c0\right)\right)} \]
    5. Applied egg-rr30.9

      \[\leadsto \frac{\frac{c0}{2}}{w} \cdot \left(2 \cdot \color{blue}{\frac{c0 \cdot \frac{d}{D}}{\left(w \cdot h\right) \cdot \frac{D}{d}}}\right) \]

    if -9.9999999999999996e-70 < (*.f64 (/.f64 c0 (*.f64 2 w)) (+.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (sqrt.f64 (-.f64 (*.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D)))) (*.f64 M M))))) < -0.0 or +inf.0 < (*.f64 (/.f64 c0 (*.f64 2 w)) (+.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (sqrt.f64 (-.f64 (*.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D)))) (*.f64 M M)))))

    1. Initial program 60.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.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. Simplified22.1

      \[\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), 0\right)} \]
    4. Applied egg-rr14.9

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\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) \leq -1 \cdot 10^{-69}:\\ \;\;\;\;\frac{\frac{c0}{2}}{w} \cdot \left(2 \cdot \frac{c0 \cdot \frac{d}{D}}{\left(w \cdot h\right) \cdot \frac{D}{d}}\right)\\ \mathbf{elif}\;\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) \leq 0:\\ \;\;\;\;\frac{M \cdot \left(h \cdot \left(M \cdot \frac{D}{d}\right)\right)}{\frac{d}{D}} \cdot 0.25\\ \mathbf{elif}\;\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) \leq \infty:\\ \;\;\;\;\frac{\frac{c0}{2}}{w} \cdot \left(2 \cdot \frac{c0 \cdot \frac{d}{D}}{\left(w \cdot h\right) \cdot \frac{D}{d}}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{M \cdot \left(h \cdot \left(M \cdot \frac{D}{d}\right)\right)}{\frac{d}{D}} \cdot 0.25\\ \end{array} \]

Alternatives

Alternative 1
Error25.4
Cost1220
\[\begin{array}{l} \mathbf{if}\;M \cdot M \leq 10^{+284}:\\ \;\;\;\;0.25 \cdot \left(D \cdot \frac{D}{\frac{d}{M \cdot M} \cdot \frac{d}{h}}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{h}{\frac{d}{M \cdot \frac{D \cdot D}{d}}} \cdot \left(M \cdot 0.25\right)\\ \end{array} \]
Alternative 2
Error18.1
Cost1220
\[\begin{array}{l} \mathbf{if}\;M \cdot M \leq 10^{+284}:\\ \;\;\;\;\frac{M \cdot \left(h \cdot \left(M \cdot \frac{D}{d}\right)\right)}{\frac{d}{D}} \cdot 0.25\\ \mathbf{else}:\\ \;\;\;\;0.25 \cdot \left(h \cdot \left(D \cdot \left(\frac{M}{d} \cdot \frac{D}{\frac{d}{M}}\right)\right)\right)\\ \end{array} \]
Alternative 3
Error28.9
Cost960
\[0.25 \cdot \left(D \cdot \frac{D}{\frac{d}{M \cdot M} \cdot \frac{d}{h}}\right) \]
Alternative 4
Error21.1
Cost960
\[0.25 \cdot \left(h \cdot \left(\frac{D}{d} \cdot \left(M \cdot \frac{D \cdot M}{d}\right)\right)\right) \]
Alternative 5
Error20.3
Cost960
\[0.25 \cdot \left(h \cdot \left(D \cdot \left(\frac{M}{d} \cdot \frac{D}{\frac{d}{M}}\right)\right)\right) \]
Alternative 6
Error31.5
Cost64
\[0 \]

Error

Reproduce

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