Average Error: 26.7 → 20.7
Time: 11.0s
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 := {\left(\frac{d}{\ell}\right)}^{0.5}\\ t_1 := {\left(\frac{d}{h}\right)}^{0.5} \cdot t_0\\ t_2 := 1 + \frac{h}{\ell} \cdot \left({\left(\frac{M \cdot D}{d \cdot 2}\right)}^{2} \cdot -0.5\right)\\ t_3 := t_1 \cdot t_2\\ t_4 := {\left(\frac{d}{h}\right)}^{0.25}\\ \mathbf{if}\;t_3 \leq -\infty:\\ \;\;\;\;t_1 \cdot \left(1 + \left(D \cdot \left(\frac{D}{d} \cdot \frac{M \cdot M}{d \cdot \frac{\ell}{h}}\right)\right) \cdot -0.125\right)\\ \mathbf{elif}\;t_3 \leq -5 \cdot 10^{-148}:\\ \;\;\;\;t_2 \cdot \left(t_0 \cdot \left(t_4 \cdot t_4\right)\right)\\ \mathbf{elif}\;t_3 \leq 0:\\ \;\;\;\;d \cdot \sqrt{\frac{\frac{1}{\ell}}{h}}\\ \mathbf{elif}\;t_3 \leq 5 \cdot 10^{+236}:\\ \;\;\;\;\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)\\ \mathbf{else}:\\ \;\;\;\;d \cdot \sqrt{\frac{1}{h \cdot \ell}}\\ \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 (pow (/ d l) 0.5))
        (t_1 (* (pow (/ d h) 0.5) t_0))
        (t_2 (+ 1.0 (* (/ h l) (* (pow (/ (* M D) (* d 2.0)) 2.0) -0.5))))
        (t_3 (* t_1 t_2))
        (t_4 (pow (/ d h) 0.25)))
   (if (<= t_3 (- INFINITY))
     (* t_1 (+ 1.0 (* (* D (* (/ D d) (/ (* M M) (* d (/ l h))))) -0.125)))
     (if (<= t_3 -5e-148)
       (* t_2 (* t_0 (* t_4 t_4)))
       (if (<= t_3 0.0)
         (* d (sqrt (/ (/ 1.0 l) h)))
         (if (<= t_3 5e+236)
           (*
            (sqrt (/ d h))
            (*
             (sqrt (/ d l))
             (fma (/ h l) (* (pow (* M (/ (/ D d) 2.0)) 2.0) -0.5) 1.0)))
           (* d (sqrt (/ 1.0 (* h l))))))))))
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 = pow((d / l), 0.5);
	double t_1 = pow((d / h), 0.5) * t_0;
	double t_2 = 1.0 + ((h / l) * (pow(((M * D) / (d * 2.0)), 2.0) * -0.5));
	double t_3 = t_1 * t_2;
	double t_4 = pow((d / h), 0.25);
	double tmp;
	if (t_3 <= -((double) INFINITY)) {
		tmp = t_1 * (1.0 + ((D * ((D / d) * ((M * M) / (d * (l / h))))) * -0.125));
	} else if (t_3 <= -5e-148) {
		tmp = t_2 * (t_0 * (t_4 * t_4));
	} else if (t_3 <= 0.0) {
		tmp = d * sqrt(((1.0 / l) / h));
	} else if (t_3 <= 5e+236) {
		tmp = sqrt((d / h)) * (sqrt((d / l)) * fma((h / l), (pow((M * ((D / d) / 2.0)), 2.0) * -0.5), 1.0));
	} else {
		tmp = d * sqrt((1.0 / (h * l)));
	}
	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 = Float64(d / l) ^ 0.5
	t_1 = Float64((Float64(d / h) ^ 0.5) * t_0)
	t_2 = Float64(1.0 + Float64(Float64(h / l) * Float64((Float64(Float64(M * D) / Float64(d * 2.0)) ^ 2.0) * -0.5)))
	t_3 = Float64(t_1 * t_2)
	t_4 = Float64(d / h) ^ 0.25
	tmp = 0.0
	if (t_3 <= Float64(-Inf))
		tmp = Float64(t_1 * Float64(1.0 + Float64(Float64(D * Float64(Float64(D / d) * Float64(Float64(M * M) / Float64(d * Float64(l / h))))) * -0.125)));
	elseif (t_3 <= -5e-148)
		tmp = Float64(t_2 * Float64(t_0 * Float64(t_4 * t_4)));
	elseif (t_3 <= 0.0)
		tmp = Float64(d * sqrt(Float64(Float64(1.0 / l) / h)));
	elseif (t_3 <= 5e+236)
		tmp = Float64(sqrt(Float64(d / h)) * Float64(sqrt(Float64(d / l)) * fma(Float64(h / l), Float64((Float64(M * Float64(Float64(D / d) / 2.0)) ^ 2.0) * -0.5), 1.0)));
	else
		tmp = Float64(d * sqrt(Float64(1.0 / Float64(h * l))));
	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[Power[N[(d / l), $MachinePrecision], 0.5], $MachinePrecision]}, Block[{t$95$1 = N[(N[Power[N[(d / h), $MachinePrecision], 0.5], $MachinePrecision] * t$95$0), $MachinePrecision]}, Block[{t$95$2 = N[(1.0 + N[(N[(h / l), $MachinePrecision] * N[(N[Power[N[(N[(M * D), $MachinePrecision] / N[(d * 2.0), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(t$95$1 * t$95$2), $MachinePrecision]}, Block[{t$95$4 = N[Power[N[(d / h), $MachinePrecision], 0.25], $MachinePrecision]}, If[LessEqual[t$95$3, (-Infinity)], N[(t$95$1 * N[(1.0 + N[(N[(D * N[(N[(D / d), $MachinePrecision] * N[(N[(M * M), $MachinePrecision] / N[(d * N[(l / h), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * -0.125), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, -5e-148], N[(t$95$2 * N[(t$95$0 * N[(t$95$4 * t$95$4), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, 0.0], N[(d * N[Sqrt[N[(N[(1.0 / l), $MachinePrecision] / h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, 5e+236], N[(N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision] * N[(N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision] * 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]), $MachinePrecision]), $MachinePrecision], N[(d * N[Sqrt[N[(1.0 / N[(h * l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]]]]]]]
\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 := {\left(\frac{d}{\ell}\right)}^{0.5}\\
t_1 := {\left(\frac{d}{h}\right)}^{0.5} \cdot t_0\\
t_2 := 1 + \frac{h}{\ell} \cdot \left({\left(\frac{M \cdot D}{d \cdot 2}\right)}^{2} \cdot -0.5\right)\\
t_3 := t_1 \cdot t_2\\
t_4 := {\left(\frac{d}{h}\right)}^{0.25}\\
\mathbf{if}\;t_3 \leq -\infty:\\
\;\;\;\;t_1 \cdot \left(1 + \left(D \cdot \left(\frac{D}{d} \cdot \frac{M \cdot M}{d \cdot \frac{\ell}{h}}\right)\right) \cdot -0.125\right)\\

\mathbf{elif}\;t_3 \leq -5 \cdot 10^{-148}:\\
\;\;\;\;t_2 \cdot \left(t_0 \cdot \left(t_4 \cdot t_4\right)\right)\\

\mathbf{elif}\;t_3 \leq 0:\\
\;\;\;\;d \cdot \sqrt{\frac{\frac{1}{\ell}}{h}}\\

\mathbf{elif}\;t_3 \leq 5 \cdot 10^{+236}:\\
\;\;\;\;\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)\\

\mathbf{else}:\\
\;\;\;\;d \cdot \sqrt{\frac{1}{h \cdot \ell}}\\


\end{array}

Error

Derivation

  1. Split input into 5 regimes
  2. if (*.f64 (*.f64 (pow.f64 (/.f64 d h) (/.f64 1 2)) (pow.f64 (/.f64 d l) (/.f64 1 2))) (-.f64 1 (*.f64 (*.f64 (/.f64 1 2) (pow.f64 (/.f64 (*.f64 M D) (*.f64 2 d)) 2)) (/.f64 h l)))) < -inf.0

    1. Initial program 64.0

      \[\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. Taylor expanded in M around 0 59.5

      \[\leadsto \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 - \color{blue}{0.125 \cdot \frac{{D}^{2} \cdot \left({M}^{2} \cdot h\right)}{\ell \cdot {d}^{2}}}\right) \]
    3. Simplified57.8

      \[\leadsto \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 - \color{blue}{0.125 \cdot \left(D \cdot \left(\frac{D}{d} \cdot \frac{M \cdot M}{d \cdot \frac{\ell}{h}}\right)\right)}\right) \]

    if -inf.0 < (*.f64 (*.f64 (pow.f64 (/.f64 d h) (/.f64 1 2)) (pow.f64 (/.f64 d l) (/.f64 1 2))) (-.f64 1 (*.f64 (*.f64 (/.f64 1 2) (pow.f64 (/.f64 (*.f64 M D) (*.f64 2 d)) 2)) (/.f64 h l)))) < -4.9999999999999999e-148

    1. Initial program 1.2

      \[\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. Applied egg-rr1.3

      \[\leadsto \left(\color{blue}{\left({\left(\frac{d}{h}\right)}^{0.25} \cdot {\left(\frac{d}{h}\right)}^{0.25}\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) \]

    if -4.9999999999999999e-148 < (*.f64 (*.f64 (pow.f64 (/.f64 d h) (/.f64 1 2)) (pow.f64 (/.f64 d l) (/.f64 1 2))) (-.f64 1 (*.f64 (*.f64 (/.f64 1 2) (pow.f64 (/.f64 (*.f64 M D) (*.f64 2 d)) 2)) (/.f64 h l)))) < -0.0

    1. Initial program 38.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. Applied egg-rr40.8

      \[\leadsto \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 - \color{blue}{\frac{\left(0.5 \cdot {\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2}\right) \cdot h}{\ell}}\right) \]
    3. Applied egg-rr40.9

      \[\leadsto \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 - \frac{\color{blue}{{\left(\sqrt[3]{0.5 \cdot \left({\left(\left(M \cdot 0.5\right) \cdot \frac{D}{d}\right)}^{2} \cdot h\right)}\right)}^{3}}}{\ell}\right) \]
    4. Taylor expanded in d around inf 30.0

      \[\leadsto \color{blue}{\sqrt{\frac{1}{\ell \cdot h}} \cdot d} \]
    5. Simplified29.8

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{\frac{1}{\ell}}{h}}} \]

    if -0.0 < (*.f64 (*.f64 (pow.f64 (/.f64 d h) (/.f64 1 2)) (pow.f64 (/.f64 d l) (/.f64 1 2))) (-.f64 1 (*.f64 (*.f64 (/.f64 1 2) (pow.f64 (/.f64 (*.f64 M D) (*.f64 2 d)) 2)) (/.f64 h l)))) < 4.9999999999999997e236

    1. Initial program 1.0

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

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

    if 4.9999999999999997e236 < (*.f64 (*.f64 (pow.f64 (/.f64 d h) (/.f64 1 2)) (pow.f64 (/.f64 d l) (/.f64 1 2))) (-.f64 1 (*.f64 (*.f64 (/.f64 1 2) (pow.f64 (/.f64 (*.f64 M D) (*.f64 2 d)) 2)) (/.f64 h l))))

    1. Initial program 60.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. Applied egg-rr56.6

      \[\leadsto \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 - \color{blue}{\frac{\left(0.5 \cdot {\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2}\right) \cdot h}{\ell}}\right) \]
    3. Applied egg-rr56.7

      \[\leadsto \left(\color{blue}{\left({\left(\frac{d}{h}\right)}^{0.25} \cdot {\left(\frac{d}{h}\right)}^{0.25}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \frac{\left(0.5 \cdot {\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2}\right) \cdot h}{\ell}\right) \]
    4. Taylor expanded in d around inf 44.3

      \[\leadsto \color{blue}{\sqrt{\frac{1}{\ell \cdot h}} \cdot d} \]
  3. Recombined 5 regimes into one program.
  4. Final simplification20.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left({\left(\frac{d}{h}\right)}^{0.5} \cdot {\left(\frac{d}{\ell}\right)}^{0.5}\right) \cdot \left(1 + \frac{h}{\ell} \cdot \left({\left(\frac{M \cdot D}{d \cdot 2}\right)}^{2} \cdot -0.5\right)\right) \leq -\infty:\\ \;\;\;\;\left({\left(\frac{d}{h}\right)}^{0.5} \cdot {\left(\frac{d}{\ell}\right)}^{0.5}\right) \cdot \left(1 + \left(D \cdot \left(\frac{D}{d} \cdot \frac{M \cdot M}{d \cdot \frac{\ell}{h}}\right)\right) \cdot -0.125\right)\\ \mathbf{elif}\;\left({\left(\frac{d}{h}\right)}^{0.5} \cdot {\left(\frac{d}{\ell}\right)}^{0.5}\right) \cdot \left(1 + \frac{h}{\ell} \cdot \left({\left(\frac{M \cdot D}{d \cdot 2}\right)}^{2} \cdot -0.5\right)\right) \leq -5 \cdot 10^{-148}:\\ \;\;\;\;\left(1 + \frac{h}{\ell} \cdot \left({\left(\frac{M \cdot D}{d \cdot 2}\right)}^{2} \cdot -0.5\right)\right) \cdot \left({\left(\frac{d}{\ell}\right)}^{0.5} \cdot \left({\left(\frac{d}{h}\right)}^{0.25} \cdot {\left(\frac{d}{h}\right)}^{0.25}\right)\right)\\ \mathbf{elif}\;\left({\left(\frac{d}{h}\right)}^{0.5} \cdot {\left(\frac{d}{\ell}\right)}^{0.5}\right) \cdot \left(1 + \frac{h}{\ell} \cdot \left({\left(\frac{M \cdot D}{d \cdot 2}\right)}^{2} \cdot -0.5\right)\right) \leq 0:\\ \;\;\;\;d \cdot \sqrt{\frac{\frac{1}{\ell}}{h}}\\ \mathbf{elif}\;\left({\left(\frac{d}{h}\right)}^{0.5} \cdot {\left(\frac{d}{\ell}\right)}^{0.5}\right) \cdot \left(1 + \frac{h}{\ell} \cdot \left({\left(\frac{M \cdot D}{d \cdot 2}\right)}^{2} \cdot -0.5\right)\right) \leq 5 \cdot 10^{+236}:\\ \;\;\;\;\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)\\ \mathbf{else}:\\ \;\;\;\;d \cdot \sqrt{\frac{1}{h \cdot \ell}}\\ \end{array} \]

Reproduce

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