Average Error: 26.3 → 19.8
Time: 12.5s
Precision: binary64
\[ \begin{array}{c}[M, D] = \mathsf{sort}([M, D])\\ \end{array} \]
\[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
\[\begin{array}{l} t_0 := \mathsf{fma}\left(\frac{h}{\ell}, {\left(M \cdot \frac{\frac{D}{d}}{2}\right)}^{2} \cdot -0.5, 1\right)\\ t_1 := t_0 \cdot \sqrt{\frac{d}{\ell}}\\ t_2 := \sqrt{\frac{d}{h}}\\ t_3 := t_1 \cdot \left(\sqrt{d} \cdot \sqrt{\frac{1}{h}}\right)\\ t_4 := \sqrt{-d}\\ \mathbf{if}\;h \leq -1 \cdot 10^{-172}:\\ \;\;\;\;t_2 \cdot \left(\frac{t_4}{\sqrt{-\ell}} \cdot t_0\right)\\ \mathbf{elif}\;h \leq 0:\\ \;\;\;\;\frac{t_4}{\sqrt{-h}} \cdot t_1\\ \mathbf{elif}\;h \leq 10^{-18}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;h \leq 10^{+158}:\\ \;\;\;\;t_2 \cdot \left(t_0 \cdot \frac{\sqrt{d}}{\sqrt{\ell}}\right)\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
(FPCore (d h l M D)
 :precision binary64
 (*
  (* (pow (/ d h) (/ 1.0 2.0)) (pow (/ d l) (/ 1.0 2.0)))
  (- 1.0 (* (* (/ 1.0 2.0) (pow (/ (* M D) (* 2.0 d)) 2.0)) (/ h l)))))
(FPCore (d h l M D)
 :precision binary64
 (let* ((t_0 (fma (/ h l) (* (pow (* M (/ (/ D d) 2.0)) 2.0) -0.5) 1.0))
        (t_1 (* t_0 (sqrt (/ d l))))
        (t_2 (sqrt (/ d h)))
        (t_3 (* t_1 (* (sqrt d) (sqrt (/ 1.0 h)))))
        (t_4 (sqrt (- d))))
   (if (<= h -1e-172)
     (* t_2 (* (/ t_4 (sqrt (- l))) t_0))
     (if (<= h 0.0)
       (* (/ t_4 (sqrt (- h))) t_1)
       (if (<= h 1e-18)
         t_3
         (if (<= h 1e+158) (* t_2 (* t_0 (/ (sqrt d) (sqrt l)))) t_3))))))
double code(double d, double h, double l, double M, double D) {
	return (pow((d / h), (1.0 / 2.0)) * pow((d / l), (1.0 / 2.0))) * (1.0 - (((1.0 / 2.0) * pow(((M * D) / (2.0 * d)), 2.0)) * (h / l)));
}
double code(double d, double h, double l, double M, double D) {
	double t_0 = fma((h / l), (pow((M * ((D / d) / 2.0)), 2.0) * -0.5), 1.0);
	double t_1 = t_0 * sqrt((d / l));
	double t_2 = sqrt((d / h));
	double t_3 = t_1 * (sqrt(d) * sqrt((1.0 / h)));
	double t_4 = sqrt(-d);
	double tmp;
	if (h <= -1e-172) {
		tmp = t_2 * ((t_4 / sqrt(-l)) * t_0);
	} else if (h <= 0.0) {
		tmp = (t_4 / sqrt(-h)) * t_1;
	} else if (h <= 1e-18) {
		tmp = t_3;
	} else if (h <= 1e+158) {
		tmp = t_2 * (t_0 * (sqrt(d) / sqrt(l)));
	} else {
		tmp = t_3;
	}
	return tmp;
}
function code(d, h, l, M, D)
	return Float64(Float64((Float64(d / h) ^ Float64(1.0 / 2.0)) * (Float64(d / l) ^ Float64(1.0 / 2.0))) * Float64(1.0 - Float64(Float64(Float64(1.0 / 2.0) * (Float64(Float64(M * D) / Float64(2.0 * d)) ^ 2.0)) * Float64(h / l))))
end
function code(d, h, l, M, D)
	t_0 = fma(Float64(h / l), Float64((Float64(M * Float64(Float64(D / d) / 2.0)) ^ 2.0) * -0.5), 1.0)
	t_1 = Float64(t_0 * sqrt(Float64(d / l)))
	t_2 = sqrt(Float64(d / h))
	t_3 = Float64(t_1 * Float64(sqrt(d) * sqrt(Float64(1.0 / h))))
	t_4 = sqrt(Float64(-d))
	tmp = 0.0
	if (h <= -1e-172)
		tmp = Float64(t_2 * Float64(Float64(t_4 / sqrt(Float64(-l))) * t_0));
	elseif (h <= 0.0)
		tmp = Float64(Float64(t_4 / sqrt(Float64(-h))) * t_1);
	elseif (h <= 1e-18)
		tmp = t_3;
	elseif (h <= 1e+158)
		tmp = Float64(t_2 * Float64(t_0 * Float64(sqrt(d) / sqrt(l))));
	else
		tmp = t_3;
	end
	return tmp
end
code[d_, h_, l_, M_, D_] := N[(N[(N[Power[N[(d / h), $MachinePrecision], N[(1.0 / 2.0), $MachinePrecision]], $MachinePrecision] * N[Power[N[(d / l), $MachinePrecision], N[(1.0 / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(1.0 - N[(N[(N[(1.0 / 2.0), $MachinePrecision] * N[Power[N[(N[(M * D), $MachinePrecision] / N[(2.0 * d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[d_, h_, l_, M_, D_] := Block[{t$95$0 = N[(N[(h / l), $MachinePrecision] * N[(N[Power[N[(M * N[(N[(D / d), $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * -0.5), $MachinePrecision] + 1.0), $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 * N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = N[(t$95$1 * N[(N[Sqrt[d], $MachinePrecision] * N[Sqrt[N[(1.0 / h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[Sqrt[(-d)], $MachinePrecision]}, If[LessEqual[h, -1e-172], N[(t$95$2 * N[(N[(t$95$4 / N[Sqrt[(-l)], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision], If[LessEqual[h, 0.0], N[(N[(t$95$4 / N[Sqrt[(-h)], $MachinePrecision]), $MachinePrecision] * t$95$1), $MachinePrecision], If[LessEqual[h, 1e-18], t$95$3, If[LessEqual[h, 1e+158], N[(t$95$2 * N[(t$95$0 * N[(N[Sqrt[d], $MachinePrecision] / N[Sqrt[l], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$3]]]]]]]]]
\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right)
\begin{array}{l}
t_0 := \mathsf{fma}\left(\frac{h}{\ell}, {\left(M \cdot \frac{\frac{D}{d}}{2}\right)}^{2} \cdot -0.5, 1\right)\\
t_1 := t_0 \cdot \sqrt{\frac{d}{\ell}}\\
t_2 := \sqrt{\frac{d}{h}}\\
t_3 := t_1 \cdot \left(\sqrt{d} \cdot \sqrt{\frac{1}{h}}\right)\\
t_4 := \sqrt{-d}\\
\mathbf{if}\;h \leq -1 \cdot 10^{-172}:\\
\;\;\;\;t_2 \cdot \left(\frac{t_4}{\sqrt{-\ell}} \cdot t_0\right)\\

\mathbf{elif}\;h \leq 0:\\
\;\;\;\;\frac{t_4}{\sqrt{-h}} \cdot t_1\\

\mathbf{elif}\;h \leq 10^{-18}:\\
\;\;\;\;t_3\\

\mathbf{elif}\;h \leq 10^{+158}:\\
\;\;\;\;t_2 \cdot \left(t_0 \cdot \frac{\sqrt{d}}{\sqrt{\ell}}\right)\\

\mathbf{else}:\\
\;\;\;\;t_3\\


\end{array}

Error

Derivation

  1. Split input into 4 regimes
  2. if h < -1e-172

    1. Initial program 23.4

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified23.6

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

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

    if -1e-172 < h < 0.0

    1. Initial program 34.5

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified34.9

      \[\leadsto \color{blue}{\sqrt{\frac{d}{h}} \cdot \left(\sqrt{\frac{d}{\ell}} \cdot \mathsf{fma}\left(\frac{h}{\ell}, {\left(M \cdot \frac{\frac{D}{d}}{2}\right)}^{2} \cdot -0.5, 1\right)\right)} \]
    3. Applied egg-rr17.1

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

    if 0.0 < h < 1.0000000000000001e-18 or 9.99999999999999953e157 < h

    1. Initial program 29.6

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified30.1

      \[\leadsto \color{blue}{\sqrt{\frac{d}{h}} \cdot \left(\sqrt{\frac{d}{\ell}} \cdot \mathsf{fma}\left(\frac{h}{\ell}, {\left(M \cdot \frac{\frac{D}{d}}{2}\right)}^{2} \cdot -0.5, 1\right)\right)} \]
    3. Applied egg-rr22.2

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

    if 1.0000000000000001e-18 < h < 9.99999999999999953e157

    1. Initial program 20.7

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified20.7

      \[\leadsto \color{blue}{\sqrt{\frac{d}{h}} \cdot \left(\sqrt{\frac{d}{\ell}} \cdot \mathsf{fma}\left(\frac{h}{\ell}, {\left(M \cdot \frac{\frac{D}{d}}{2}\right)}^{2} \cdot -0.5, 1\right)\right)} \]
    3. Applied egg-rr15.2

      \[\leadsto \sqrt{\frac{d}{h}} \cdot \left(\color{blue}{\frac{\sqrt{d}}{\sqrt{\ell}}} \cdot \mathsf{fma}\left(\frac{h}{\ell}, {\left(M \cdot \frac{\frac{D}{d}}{2}\right)}^{2} \cdot -0.5, 1\right)\right) \]
  3. Recombined 4 regimes into one program.
  4. Final simplification19.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;h \leq -1 \cdot 10^{-172}:\\ \;\;\;\;\sqrt{\frac{d}{h}} \cdot \left(\frac{\sqrt{-d}}{\sqrt{-\ell}} \cdot \mathsf{fma}\left(\frac{h}{\ell}, {\left(M \cdot \frac{\frac{D}{d}}{2}\right)}^{2} \cdot -0.5, 1\right)\right)\\ \mathbf{elif}\;h \leq 0:\\ \;\;\;\;\frac{\sqrt{-d}}{\sqrt{-h}} \cdot \left(\mathsf{fma}\left(\frac{h}{\ell}, {\left(M \cdot \frac{\frac{D}{d}}{2}\right)}^{2} \cdot -0.5, 1\right) \cdot \sqrt{\frac{d}{\ell}}\right)\\ \mathbf{elif}\;h \leq 10^{-18}:\\ \;\;\;\;\left(\mathsf{fma}\left(\frac{h}{\ell}, {\left(M \cdot \frac{\frac{D}{d}}{2}\right)}^{2} \cdot -0.5, 1\right) \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(\sqrt{d} \cdot \sqrt{\frac{1}{h}}\right)\\ \mathbf{elif}\;h \leq 10^{+158}:\\ \;\;\;\;\sqrt{\frac{d}{h}} \cdot \left(\mathsf{fma}\left(\frac{h}{\ell}, {\left(M \cdot \frac{\frac{D}{d}}{2}\right)}^{2} \cdot -0.5, 1\right) \cdot \frac{\sqrt{d}}{\sqrt{\ell}}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\mathsf{fma}\left(\frac{h}{\ell}, {\left(M \cdot \frac{\frac{D}{d}}{2}\right)}^{2} \cdot -0.5, 1\right) \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(\sqrt{d} \cdot \sqrt{\frac{1}{h}}\right)\\ \end{array} \]

Reproduce

herbie shell --seed 2022197 
(FPCore (d h l M D)
  :name "Henrywood and Agarwal, Equation (12)"
  :precision binary64
  (* (* (pow (/ d h) (/ 1.0 2.0)) (pow (/ d l) (/ 1.0 2.0))) (- 1.0 (* (* (/ 1.0 2.0) (pow (/ (* M D) (* 2.0 d)) 2.0)) (/ h l)))))