Average Error: 26.7 → 20.8
Time: 12.4s
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 := 1 - \left(0.5 \cdot {\left(\frac{M \cdot D}{d \cdot 2}\right)}^{2}\right) \cdot \frac{h}{\ell}\\ t_1 := {\left(\frac{d}{h}\right)}^{0.5}\\ t_2 := \left(t_1 \cdot {\left(\frac{d}{\ell}\right)}^{0.5}\right) \cdot t_0\\ t_3 := t_1 \cdot \sqrt{\frac{d}{\ell}}\\ \mathbf{if}\;t_2 \leq -1 \cdot 10^{-219}:\\ \;\;\;\;t_3 \cdot \left(1 + \left(\frac{h}{\ell} \cdot {\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2}\right) \cdot -0.5\right)\\ \mathbf{elif}\;t_2 \leq 0:\\ \;\;\;\;d \cdot \sqrt{\frac{\frac{1}{h}}{\ell}}\\ \mathbf{elif}\;t_2 \leq 2 \cdot 10^{+290}:\\ \;\;\;\;t_0 \cdot t_3\\ \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 (- 1.0 (* (* 0.5 (pow (/ (* M D) (* d 2.0)) 2.0)) (/ h l))))
        (t_1 (pow (/ d h) 0.5))
        (t_2 (* (* t_1 (pow (/ d l) 0.5)) t_0))
        (t_3 (* t_1 (sqrt (/ d l)))))
   (if (<= t_2 -1e-219)
     (* t_3 (+ 1.0 (* (* (/ h l) (pow (* (/ M 2.0) (/ D d)) 2.0)) -0.5)))
     (if (<= t_2 0.0)
       (* d (sqrt (/ (/ 1.0 h) l)))
       (if (<= t_2 2e+290) (* t_0 t_3) (* 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 = 1.0 - ((0.5 * pow(((M * D) / (d * 2.0)), 2.0)) * (h / l));
	double t_1 = pow((d / h), 0.5);
	double t_2 = (t_1 * pow((d / l), 0.5)) * t_0;
	double t_3 = t_1 * sqrt((d / l));
	double tmp;
	if (t_2 <= -1e-219) {
		tmp = t_3 * (1.0 + (((h / l) * pow(((M / 2.0) * (D / d)), 2.0)) * -0.5));
	} else if (t_2 <= 0.0) {
		tmp = d * sqrt(((1.0 / h) / l));
	} else if (t_2 <= 2e+290) {
		tmp = t_0 * t_3;
	} else {
		tmp = d * sqrt((1.0 / (h * l)));
	}
	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) :: t_1
    real(8) :: t_2
    real(8) :: t_3
    real(8) :: tmp
    t_0 = 1.0d0 - ((0.5d0 * (((m * d_1) / (d * 2.0d0)) ** 2.0d0)) * (h / l))
    t_1 = (d / h) ** 0.5d0
    t_2 = (t_1 * ((d / l) ** 0.5d0)) * t_0
    t_3 = t_1 * sqrt((d / l))
    if (t_2 <= (-1d-219)) then
        tmp = t_3 * (1.0d0 + (((h / l) * (((m / 2.0d0) * (d_1 / d)) ** 2.0d0)) * (-0.5d0)))
    else if (t_2 <= 0.0d0) then
        tmp = d * sqrt(((1.0d0 / h) / l))
    else if (t_2 <= 2d+290) then
        tmp = t_0 * t_3
    else
        tmp = d * sqrt((1.0d0 / (h * l)))
    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 = 1.0 - ((0.5 * Math.pow(((M * D) / (d * 2.0)), 2.0)) * (h / l));
	double t_1 = Math.pow((d / h), 0.5);
	double t_2 = (t_1 * Math.pow((d / l), 0.5)) * t_0;
	double t_3 = t_1 * Math.sqrt((d / l));
	double tmp;
	if (t_2 <= -1e-219) {
		tmp = t_3 * (1.0 + (((h / l) * Math.pow(((M / 2.0) * (D / d)), 2.0)) * -0.5));
	} else if (t_2 <= 0.0) {
		tmp = d * Math.sqrt(((1.0 / h) / l));
	} else if (t_2 <= 2e+290) {
		tmp = t_0 * t_3;
	} else {
		tmp = d * Math.sqrt((1.0 / (h * l)));
	}
	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 = 1.0 - ((0.5 * math.pow(((M * D) / (d * 2.0)), 2.0)) * (h / l))
	t_1 = math.pow((d / h), 0.5)
	t_2 = (t_1 * math.pow((d / l), 0.5)) * t_0
	t_3 = t_1 * math.sqrt((d / l))
	tmp = 0
	if t_2 <= -1e-219:
		tmp = t_3 * (1.0 + (((h / l) * math.pow(((M / 2.0) * (D / d)), 2.0)) * -0.5))
	elif t_2 <= 0.0:
		tmp = d * math.sqrt(((1.0 / h) / l))
	elif t_2 <= 2e+290:
		tmp = t_0 * t_3
	else:
		tmp = d * math.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(1.0 - Float64(Float64(0.5 * (Float64(Float64(M * D) / Float64(d * 2.0)) ^ 2.0)) * Float64(h / l)))
	t_1 = Float64(d / h) ^ 0.5
	t_2 = Float64(Float64(t_1 * (Float64(d / l) ^ 0.5)) * t_0)
	t_3 = Float64(t_1 * sqrt(Float64(d / l)))
	tmp = 0.0
	if (t_2 <= -1e-219)
		tmp = Float64(t_3 * Float64(1.0 + Float64(Float64(Float64(h / l) * (Float64(Float64(M / 2.0) * Float64(D / d)) ^ 2.0)) * -0.5)));
	elseif (t_2 <= 0.0)
		tmp = Float64(d * sqrt(Float64(Float64(1.0 / h) / l)));
	elseif (t_2 <= 2e+290)
		tmp = Float64(t_0 * t_3);
	else
		tmp = Float64(d * sqrt(Float64(1.0 / Float64(h * l))));
	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 = 1.0 - ((0.5 * (((M * D) / (d * 2.0)) ^ 2.0)) * (h / l));
	t_1 = (d / h) ^ 0.5;
	t_2 = (t_1 * ((d / l) ^ 0.5)) * t_0;
	t_3 = t_1 * sqrt((d / l));
	tmp = 0.0;
	if (t_2 <= -1e-219)
		tmp = t_3 * (1.0 + (((h / l) * (((M / 2.0) * (D / d)) ^ 2.0)) * -0.5));
	elseif (t_2 <= 0.0)
		tmp = d * sqrt(((1.0 / h) / l));
	elseif (t_2 <= 2e+290)
		tmp = t_0 * t_3;
	else
		tmp = d * sqrt((1.0 / (h * l)));
	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[(1.0 - N[(N[(0.5 * N[Power[N[(N[(M * D), $MachinePrecision] / N[(d * 2.0), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Power[N[(d / h), $MachinePrecision], 0.5], $MachinePrecision]}, Block[{t$95$2 = N[(N[(t$95$1 * N[Power[N[(d / l), $MachinePrecision], 0.5], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision]}, Block[{t$95$3 = N[(t$95$1 * N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, -1e-219], N[(t$95$3 * N[(1.0 + N[(N[(N[(h / l), $MachinePrecision] * N[Power[N[(N[(M / 2.0), $MachinePrecision] * N[(D / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 0.0], N[(d * N[Sqrt[N[(N[(1.0 / h), $MachinePrecision] / l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 2e+290], N[(t$95$0 * t$95$3), $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 := 1 - \left(0.5 \cdot {\left(\frac{M \cdot D}{d \cdot 2}\right)}^{2}\right) \cdot \frac{h}{\ell}\\
t_1 := {\left(\frac{d}{h}\right)}^{0.5}\\
t_2 := \left(t_1 \cdot {\left(\frac{d}{\ell}\right)}^{0.5}\right) \cdot t_0\\
t_3 := t_1 \cdot \sqrt{\frac{d}{\ell}}\\
\mathbf{if}\;t_2 \leq -1 \cdot 10^{-219}:\\
\;\;\;\;t_3 \cdot \left(1 + \left(\frac{h}{\ell} \cdot {\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2}\right) \cdot -0.5\right)\\

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

\mathbf{elif}\;t_2 \leq 2 \cdot 10^{+290}:\\
\;\;\;\;t_0 \cdot t_3\\

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


\end{array}

Error

Bits error versus d

Bits error versus h

Bits error versus l

Bits error versus M

Bits error versus D

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 4 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)))) < -1e-219

    1. Initial program 27.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. Applied egg-rr27.1

      \[\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) \]
    3. Applied egg-rr28.5

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

    if -1e-219 < (*.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 41.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) \]
    2. Applied egg-rr41.3

      \[\leadsto \left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot \color{blue}{\left({\left(\frac{d}{\ell}\right)}^{0.25} \cdot {\left(\frac{d}{\ell}\right)}^{0.25}\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. Taylor expanded in d around inf 30.2

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

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

    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)))) < 2.00000000000000012e290

    1. Initial program 0.9

      \[\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-rr0.9

      \[\leadsto \left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot \color{blue}{\sqrt{\frac{d}{\ell}}}\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 2.00000000000000012e290 < (*.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 63.9

      \[\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 d around inf 45.7

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

    \[\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 - \left(0.5 \cdot {\left(\frac{M \cdot D}{d \cdot 2}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \leq -1 \cdot 10^{-219}:\\ \;\;\;\;\left({\left(\frac{d}{h}\right)}^{0.5} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 + \left(\frac{h}{\ell} \cdot {\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2}\right) \cdot -0.5\right)\\ \mathbf{elif}\;\left({\left(\frac{d}{h}\right)}^{0.5} \cdot {\left(\frac{d}{\ell}\right)}^{0.5}\right) \cdot \left(1 - \left(0.5 \cdot {\left(\frac{M \cdot D}{d \cdot 2}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \leq 0:\\ \;\;\;\;d \cdot \sqrt{\frac{\frac{1}{h}}{\ell}}\\ \mathbf{elif}\;\left({\left(\frac{d}{h}\right)}^{0.5} \cdot {\left(\frac{d}{\ell}\right)}^{0.5}\right) \cdot \left(1 - \left(0.5 \cdot {\left(\frac{M \cdot D}{d \cdot 2}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \leq 2 \cdot 10^{+290}:\\ \;\;\;\;\left(1 - \left(0.5 \cdot {\left(\frac{M \cdot D}{d \cdot 2}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \cdot \left({\left(\frac{d}{h}\right)}^{0.5} \cdot \sqrt{\frac{d}{\ell}}\right)\\ \mathbf{else}:\\ \;\;\;\;d \cdot \sqrt{\frac{1}{h \cdot \ell}}\\ \end{array} \]

Reproduce

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