Average Error: 26.6 → 18.9
Time: 12.2s
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}\\ \mathbf{if}\;\ell \leq -1 \cdot 10^{-50}:\\ \;\;\;\;\left(\frac{1}{\frac{\sqrt{-h}}{\sqrt{-d}}} \cdot t_0\right) \cdot \left(1 - {\left(\sqrt{\frac{h}{\ell}} \cdot \left(\frac{M \cdot \left(0.5 \cdot D\right)}{d} \cdot \sqrt{0.5}\right)\right)}^{2}\right)\\ \mathbf{elif}\;\ell \leq 10^{-150}:\\ \;\;\;\;\left(t_0 \cdot {\left(\frac{d}{h}\right)}^{0.5}\right) \cdot \left(1 + \frac{-1}{\frac{\ell}{{\left(\left(0.5 \cdot M\right) \cdot \frac{D}{d}\right)}^{2} \cdot \left(h \cdot 0.5\right)}}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(t_0 \cdot \frac{\sqrt{d}}{\sqrt{h}}\right) \cdot \left(1 - \frac{h}{\ell} \cdot \left(0.5 \cdot {\left(\frac{M \cdot D}{d \cdot 2}\right)}^{2}\right)\right)\\ \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)))
   (if (<= l -1e-50)
     (*
      (* (/ 1.0 (/ (sqrt (- h)) (sqrt (- d)))) t_0)
      (-
       1.0
       (pow (* (sqrt (/ h l)) (* (/ (* M (* 0.5 D)) d) (sqrt 0.5))) 2.0)))
     (if (<= l 1e-150)
       (*
        (* t_0 (pow (/ d h) 0.5))
        (+ 1.0 (/ -1.0 (/ l (* (pow (* (* 0.5 M) (/ D d)) 2.0) (* h 0.5))))))
       (*
        (* t_0 (/ (sqrt d) (sqrt h)))
        (- 1.0 (* (/ h l) (* 0.5 (pow (/ (* M D) (* d 2.0)) 2.0)))))))))
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 tmp;
	if (l <= -1e-50) {
		tmp = ((1.0 / (sqrt(-h) / sqrt(-d))) * t_0) * (1.0 - pow((sqrt((h / l)) * (((M * (0.5 * D)) / d) * sqrt(0.5))), 2.0));
	} else if (l <= 1e-150) {
		tmp = (t_0 * pow((d / h), 0.5)) * (1.0 + (-1.0 / (l / (pow(((0.5 * M) * (D / d)), 2.0) * (h * 0.5)))));
	} else {
		tmp = (t_0 * (sqrt(d) / sqrt(h))) * (1.0 - ((h / l) * (0.5 * pow(((M * D) / (d * 2.0)), 2.0))));
	}
	return tmp;
}
real(8) function code(d, h, l, m, d_1)
    real(8), intent (in) :: d
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: m
    real(8), intent (in) :: d_1
    code = (((d / h) ** (1.0d0 / 2.0d0)) * ((d / l) ** (1.0d0 / 2.0d0))) * (1.0d0 - (((1.0d0 / 2.0d0) * (((m * d_1) / (2.0d0 * d)) ** 2.0d0)) * (h / l)))
end function
real(8) function code(d, h, l, m, d_1)
    real(8), intent (in) :: d
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: m
    real(8), intent (in) :: d_1
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (d / l) ** 0.5d0
    if (l <= (-1d-50)) then
        tmp = ((1.0d0 / (sqrt(-h) / sqrt(-d))) * t_0) * (1.0d0 - ((sqrt((h / l)) * (((m * (0.5d0 * d_1)) / d) * sqrt(0.5d0))) ** 2.0d0))
    else if (l <= 1d-150) then
        tmp = (t_0 * ((d / h) ** 0.5d0)) * (1.0d0 + ((-1.0d0) / (l / ((((0.5d0 * m) * (d_1 / d)) ** 2.0d0) * (h * 0.5d0)))))
    else
        tmp = (t_0 * (sqrt(d) / sqrt(h))) * (1.0d0 - ((h / l) * (0.5d0 * (((m * d_1) / (d * 2.0d0)) ** 2.0d0))))
    end if
    code = tmp
end function
public static double code(double d, double h, double l, double M, double D) {
	return (Math.pow((d / h), (1.0 / 2.0)) * Math.pow((d / l), (1.0 / 2.0))) * (1.0 - (((1.0 / 2.0) * Math.pow(((M * D) / (2.0 * d)), 2.0)) * (h / l)));
}
public static double code(double d, double h, double l, double M, double D) {
	double t_0 = Math.pow((d / l), 0.5);
	double tmp;
	if (l <= -1e-50) {
		tmp = ((1.0 / (Math.sqrt(-h) / Math.sqrt(-d))) * t_0) * (1.0 - Math.pow((Math.sqrt((h / l)) * (((M * (0.5 * D)) / d) * Math.sqrt(0.5))), 2.0));
	} else if (l <= 1e-150) {
		tmp = (t_0 * Math.pow((d / h), 0.5)) * (1.0 + (-1.0 / (l / (Math.pow(((0.5 * M) * (D / d)), 2.0) * (h * 0.5)))));
	} else {
		tmp = (t_0 * (Math.sqrt(d) / Math.sqrt(h))) * (1.0 - ((h / l) * (0.5 * Math.pow(((M * D) / (d * 2.0)), 2.0))));
	}
	return tmp;
}
def code(d, h, l, M, D):
	return (math.pow((d / h), (1.0 / 2.0)) * math.pow((d / l), (1.0 / 2.0))) * (1.0 - (((1.0 / 2.0) * math.pow(((M * D) / (2.0 * d)), 2.0)) * (h / l)))
def code(d, h, l, M, D):
	t_0 = math.pow((d / l), 0.5)
	tmp = 0
	if l <= -1e-50:
		tmp = ((1.0 / (math.sqrt(-h) / math.sqrt(-d))) * t_0) * (1.0 - math.pow((math.sqrt((h / l)) * (((M * (0.5 * D)) / d) * math.sqrt(0.5))), 2.0))
	elif l <= 1e-150:
		tmp = (t_0 * math.pow((d / h), 0.5)) * (1.0 + (-1.0 / (l / (math.pow(((0.5 * M) * (D / d)), 2.0) * (h * 0.5)))))
	else:
		tmp = (t_0 * (math.sqrt(d) / math.sqrt(h))) * (1.0 - ((h / l) * (0.5 * math.pow(((M * D) / (d * 2.0)), 2.0))))
	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
	tmp = 0.0
	if (l <= -1e-50)
		tmp = Float64(Float64(Float64(1.0 / Float64(sqrt(Float64(-h)) / sqrt(Float64(-d)))) * t_0) * Float64(1.0 - (Float64(sqrt(Float64(h / l)) * Float64(Float64(Float64(M * Float64(0.5 * D)) / d) * sqrt(0.5))) ^ 2.0)));
	elseif (l <= 1e-150)
		tmp = Float64(Float64(t_0 * (Float64(d / h) ^ 0.5)) * Float64(1.0 + Float64(-1.0 / Float64(l / Float64((Float64(Float64(0.5 * M) * Float64(D / d)) ^ 2.0) * Float64(h * 0.5))))));
	else
		tmp = Float64(Float64(t_0 * Float64(sqrt(d) / sqrt(h))) * Float64(1.0 - Float64(Float64(h / l) * Float64(0.5 * (Float64(Float64(M * D) / Float64(d * 2.0)) ^ 2.0)))));
	end
	return tmp
end
function tmp = code(d, h, l, M, D)
	tmp = (((d / h) ^ (1.0 / 2.0)) * ((d / l) ^ (1.0 / 2.0))) * (1.0 - (((1.0 / 2.0) * (((M * D) / (2.0 * d)) ^ 2.0)) * (h / l)));
end
function tmp_2 = code(d, h, l, M, D)
	t_0 = (d / l) ^ 0.5;
	tmp = 0.0;
	if (l <= -1e-50)
		tmp = ((1.0 / (sqrt(-h) / sqrt(-d))) * t_0) * (1.0 - ((sqrt((h / l)) * (((M * (0.5 * D)) / d) * sqrt(0.5))) ^ 2.0));
	elseif (l <= 1e-150)
		tmp = (t_0 * ((d / h) ^ 0.5)) * (1.0 + (-1.0 / (l / ((((0.5 * M) * (D / d)) ^ 2.0) * (h * 0.5)))));
	else
		tmp = (t_0 * (sqrt(d) / sqrt(h))) * (1.0 - ((h / l) * (0.5 * (((M * D) / (d * 2.0)) ^ 2.0))));
	end
	tmp_2 = 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]}, If[LessEqual[l, -1e-50], N[(N[(N[(1.0 / N[(N[Sqrt[(-h)], $MachinePrecision] / N[Sqrt[(-d)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision] * N[(1.0 - N[Power[N[(N[Sqrt[N[(h / l), $MachinePrecision]], $MachinePrecision] * N[(N[(N[(M * N[(0.5 * D), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision] * N[Sqrt[0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 1e-150], N[(N[(t$95$0 * N[Power[N[(d / h), $MachinePrecision], 0.5], $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[(-1.0 / N[(l / N[(N[Power[N[(N[(0.5 * M), $MachinePrecision] * N[(D / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(h * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 * N[(N[Sqrt[d], $MachinePrecision] / N[Sqrt[h], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 - N[(N[(h / l), $MachinePrecision] * N[(0.5 * N[Power[N[(N[(M * D), $MachinePrecision] / N[(d * 2.0), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $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}\\
\mathbf{if}\;\ell \leq -1 \cdot 10^{-50}:\\
\;\;\;\;\left(\frac{1}{\frac{\sqrt{-h}}{\sqrt{-d}}} \cdot t_0\right) \cdot \left(1 - {\left(\sqrt{\frac{h}{\ell}} \cdot \left(\frac{M \cdot \left(0.5 \cdot D\right)}{d} \cdot \sqrt{0.5}\right)\right)}^{2}\right)\\

\mathbf{elif}\;\ell \leq 10^{-150}:\\
\;\;\;\;\left(t_0 \cdot {\left(\frac{d}{h}\right)}^{0.5}\right) \cdot \left(1 + \frac{-1}{\frac{\ell}{{\left(\left(0.5 \cdot M\right) \cdot \frac{D}{d}\right)}^{2} \cdot \left(h \cdot 0.5\right)}}\right)\\

\mathbf{else}:\\
\;\;\;\;\left(t_0 \cdot \frac{\sqrt{d}}{\sqrt{h}}\right) \cdot \left(1 - \frac{h}{\ell} \cdot \left(0.5 \cdot {\left(\frac{M \cdot D}{d \cdot 2}\right)}^{2}\right)\right)\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 3 regimes
  2. if l < -1.00000000000000001e-50

    1. Initial program 25.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-rr25.3

      \[\leadsto \left(\color{blue}{\frac{1}{\sqrt{\frac{h}{d}}}} \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) \]
    3. Applied egg-rr23.7

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

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

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

    if -1.00000000000000001e-50 < l < 1.00000000000000001e-150

    1. Initial program 31.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-rr26.0

      \[\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{1}{\frac{\ell}{{\left(\left(M \cdot 0.5\right) \cdot \frac{D}{d}\right)}^{2} \cdot \left(0.5 \cdot h\right)}}}\right) \]

    if 1.00000000000000001e-150 < l

    1. Initial program 25.1

      \[\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-rr17.7

      \[\leadsto \left(\color{blue}{\frac{\sqrt{d}}{\sqrt{h}}} \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) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification18.9

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

Reproduce

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