Average Error: 14.0 → 8.6
Time: 19.1s
Precision: binary64
Cost: 14212
\[ \begin{array}{c}[M, D] = \mathsf{sort}([M, D])\\ \end{array} \]
\[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]
\[\begin{array}{l} \mathbf{if}\;\frac{h}{\ell} \leq -4 \cdot 10^{+264}:\\ \;\;\;\;w0 \cdot \sqrt{1 - \left(h \cdot {\left(\frac{M}{\frac{d}{D \cdot 0.5}}\right)}^{2}\right) \cdot \frac{1}{\ell}}\\ \mathbf{elif}\;\frac{h}{\ell} \leq -5 \cdot 10^{-303}:\\ \;\;\;\;w0 \cdot \sqrt{1 - \frac{\frac{M}{d}}{\frac{4}{D}} \cdot \left(\frac{h}{\ell} \cdot \frac{D}{\frac{d}{M}}\right)}\\ \mathbf{else}:\\ \;\;\;\;w0\\ \end{array} \]
(FPCore (w0 M D h l d)
 :precision binary64
 (* w0 (sqrt (- 1.0 (* (pow (/ (* M D) (* 2.0 d)) 2.0) (/ h l))))))
(FPCore (w0 M D h l d)
 :precision binary64
 (if (<= (/ h l) -4e+264)
   (* w0 (sqrt (- 1.0 (* (* h (pow (/ M (/ d (* D 0.5))) 2.0)) (/ 1.0 l)))))
   (if (<= (/ h l) -5e-303)
     (* w0 (sqrt (- 1.0 (* (/ (/ M d) (/ 4.0 D)) (* (/ h l) (/ D (/ d M)))))))
     w0)))
double code(double w0, double M, double D, double h, double l, double d) {
	return w0 * sqrt((1.0 - (pow(((M * D) / (2.0 * d)), 2.0) * (h / l))));
}
double code(double w0, double M, double D, double h, double l, double d) {
	double tmp;
	if ((h / l) <= -4e+264) {
		tmp = w0 * sqrt((1.0 - ((h * pow((M / (d / (D * 0.5))), 2.0)) * (1.0 / l))));
	} else if ((h / l) <= -5e-303) {
		tmp = w0 * sqrt((1.0 - (((M / d) / (4.0 / D)) * ((h / l) * (D / (d / M))))));
	} else {
		tmp = w0;
	}
	return tmp;
}
real(8) function code(w0, m, d, h, l, d_1)
    real(8), intent (in) :: w0
    real(8), intent (in) :: m
    real(8), intent (in) :: d
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: d_1
    code = w0 * sqrt((1.0d0 - ((((m * d) / (2.0d0 * d_1)) ** 2.0d0) * (h / l))))
end function
real(8) function code(w0, m, d, h, l, d_1)
    real(8), intent (in) :: w0
    real(8), intent (in) :: m
    real(8), intent (in) :: d
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: d_1
    real(8) :: tmp
    if ((h / l) <= (-4d+264)) then
        tmp = w0 * sqrt((1.0d0 - ((h * ((m / (d_1 / (d * 0.5d0))) ** 2.0d0)) * (1.0d0 / l))))
    else if ((h / l) <= (-5d-303)) then
        tmp = w0 * sqrt((1.0d0 - (((m / d_1) / (4.0d0 / d)) * ((h / l) * (d / (d_1 / m))))))
    else
        tmp = w0
    end if
    code = tmp
end function
public static double code(double w0, double M, double D, double h, double l, double d) {
	return w0 * Math.sqrt((1.0 - (Math.pow(((M * D) / (2.0 * d)), 2.0) * (h / l))));
}
public static double code(double w0, double M, double D, double h, double l, double d) {
	double tmp;
	if ((h / l) <= -4e+264) {
		tmp = w0 * Math.sqrt((1.0 - ((h * Math.pow((M / (d / (D * 0.5))), 2.0)) * (1.0 / l))));
	} else if ((h / l) <= -5e-303) {
		tmp = w0 * Math.sqrt((1.0 - (((M / d) / (4.0 / D)) * ((h / l) * (D / (d / M))))));
	} else {
		tmp = w0;
	}
	return tmp;
}
def code(w0, M, D, h, l, d):
	return w0 * math.sqrt((1.0 - (math.pow(((M * D) / (2.0 * d)), 2.0) * (h / l))))
def code(w0, M, D, h, l, d):
	tmp = 0
	if (h / l) <= -4e+264:
		tmp = w0 * math.sqrt((1.0 - ((h * math.pow((M / (d / (D * 0.5))), 2.0)) * (1.0 / l))))
	elif (h / l) <= -5e-303:
		tmp = w0 * math.sqrt((1.0 - (((M / d) / (4.0 / D)) * ((h / l) * (D / (d / M))))))
	else:
		tmp = w0
	return tmp
function code(w0, M, D, h, l, d)
	return Float64(w0 * sqrt(Float64(1.0 - Float64((Float64(Float64(M * D) / Float64(2.0 * d)) ^ 2.0) * Float64(h / l)))))
end
function code(w0, M, D, h, l, d)
	tmp = 0.0
	if (Float64(h / l) <= -4e+264)
		tmp = Float64(w0 * sqrt(Float64(1.0 - Float64(Float64(h * (Float64(M / Float64(d / Float64(D * 0.5))) ^ 2.0)) * Float64(1.0 / l)))));
	elseif (Float64(h / l) <= -5e-303)
		tmp = Float64(w0 * sqrt(Float64(1.0 - Float64(Float64(Float64(M / d) / Float64(4.0 / D)) * Float64(Float64(h / l) * Float64(D / Float64(d / M)))))));
	else
		tmp = w0;
	end
	return tmp
end
function tmp = code(w0, M, D, h, l, d)
	tmp = w0 * sqrt((1.0 - ((((M * D) / (2.0 * d)) ^ 2.0) * (h / l))));
end
function tmp_2 = code(w0, M, D, h, l, d)
	tmp = 0.0;
	if ((h / l) <= -4e+264)
		tmp = w0 * sqrt((1.0 - ((h * ((M / (d / (D * 0.5))) ^ 2.0)) * (1.0 / l))));
	elseif ((h / l) <= -5e-303)
		tmp = w0 * sqrt((1.0 - (((M / d) / (4.0 / D)) * ((h / l) * (D / (d / M))))));
	else
		tmp = w0;
	end
	tmp_2 = tmp;
end
code[w0_, M_, D_, h_, l_, d_] := N[(w0 * N[Sqrt[N[(1.0 - N[(N[Power[N[(N[(M * D), $MachinePrecision] / N[(2.0 * d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
code[w0_, M_, D_, h_, l_, d_] := If[LessEqual[N[(h / l), $MachinePrecision], -4e+264], N[(w0 * N[Sqrt[N[(1.0 - N[(N[(h * N[Power[N[(M / N[(d / N[(D * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] * N[(1.0 / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(h / l), $MachinePrecision], -5e-303], N[(w0 * N[Sqrt[N[(1.0 - N[(N[(N[(M / d), $MachinePrecision] / N[(4.0 / D), $MachinePrecision]), $MachinePrecision] * N[(N[(h / l), $MachinePrecision] * N[(D / N[(d / M), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], w0]]
w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}}
\begin{array}{l}
\mathbf{if}\;\frac{h}{\ell} \leq -4 \cdot 10^{+264}:\\
\;\;\;\;w0 \cdot \sqrt{1 - \left(h \cdot {\left(\frac{M}{\frac{d}{D \cdot 0.5}}\right)}^{2}\right) \cdot \frac{1}{\ell}}\\

\mathbf{elif}\;\frac{h}{\ell} \leq -5 \cdot 10^{-303}:\\
\;\;\;\;w0 \cdot \sqrt{1 - \frac{\frac{M}{d}}{\frac{4}{D}} \cdot \left(\frac{h}{\ell} \cdot \frac{D}{\frac{d}{M}}\right)}\\

\mathbf{else}:\\
\;\;\;\;w0\\


\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 (/.f64 h l) < -4.00000000000000018e264

    1. Initial program 52.3

      \[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]
    2. Applied egg-rr24.1

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

      \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\left(h \cdot {\left(\frac{M}{\frac{d}{D \cdot 0.5}}\right)}^{2}\right) \cdot \frac{1}{\ell}}} \]
      Proof
      (*.f64 w0 (sqrt.f64 (-.f64 1 (*.f64 (*.f64 h (pow.f64 (/.f64 M (/.f64 d (*.f64 D 1/2))) 2)) (/.f64 1 l))))): 0 points increase in error, 0 points decrease in error
      (*.f64 w0 (sqrt.f64 (-.f64 1 (*.f64 (*.f64 h (pow.f64 (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 M (*.f64 D 1/2)) d)) 2)) (/.f64 1 l))))): 6 points increase in error, 0 points decrease in error
      (*.f64 w0 (sqrt.f64 (-.f64 1 (*.f64 (*.f64 h (pow.f64 (Rewrite<= associate-*r/_binary64 (*.f64 M (/.f64 (*.f64 D 1/2) d))) 2)) (/.f64 1 l))))): 0 points increase in error, 6 points decrease in error
      (*.f64 w0 (sqrt.f64 (-.f64 1 (*.f64 (*.f64 h (pow.f64 (*.f64 M (Rewrite<= associate-*l/_binary64 (*.f64 (/.f64 D d) 1/2))) 2)) (/.f64 1 l))))): 0 points increase in error, 0 points decrease in error
      (*.f64 w0 (sqrt.f64 (-.f64 1 (*.f64 (*.f64 h (pow.f64 (*.f64 M (Rewrite<= *-commutative_binary64 (*.f64 1/2 (/.f64 D d)))) 2)) (/.f64 1 l))))): 0 points increase in error, 0 points decrease in error
      (*.f64 w0 (sqrt.f64 (-.f64 1 (*.f64 (Rewrite<= *-commutative_binary64 (*.f64 (pow.f64 (*.f64 M (*.f64 1/2 (/.f64 D d))) 2) h)) (/.f64 1 l))))): 0 points increase in error, 0 points decrease in error
      (*.f64 w0 (sqrt.f64 (-.f64 1 (Rewrite<= *-commutative_binary64 (*.f64 (/.f64 1 l) (*.f64 (pow.f64 (*.f64 M (*.f64 1/2 (/.f64 D d))) 2) h)))))): 8 points increase in error, 0 points decrease in error
      (*.f64 w0 (sqrt.f64 (-.f64 1 (Rewrite<= associate-/r/_binary64 (/.f64 1 (/.f64 l (*.f64 (pow.f64 (*.f64 M (*.f64 1/2 (/.f64 D d))) 2) h))))))): 0 points increase in error, 8 points decrease in error

    if -4.00000000000000018e264 < (/.f64 h l) < -4.9999999999999998e-303

    1. Initial program 14.0

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

      \[\leadsto \color{blue}{w0 \cdot \sqrt{1 - {\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}}} \]
      Proof
      (*.f64 w0 (sqrt.f64 (-.f64 1 (*.f64 (pow.f64 (*.f64 (/.f64 M 2) (/.f64 D d)) 2) (/.f64 h l))))): 0 points increase in error, 0 points decrease in error
      (*.f64 w0 (sqrt.f64 (-.f64 1 (*.f64 (pow.f64 (Rewrite<= times-frac_binary64 (/.f64 (*.f64 M D) (*.f64 2 d))) 2) (/.f64 h l))))): 1 points increase in error, 0 points decrease in error
    3. Applied egg-rr14.0

      \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\frac{\left(\frac{M}{d} \cdot D\right) \cdot \left(\frac{M}{d} \cdot D\right)}{\frac{\ell}{h} \cdot 4}}} \]
    4. Applied egg-rr11.9

      \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\frac{\frac{M}{d}}{\frac{4}{D}} \cdot \left(\left(\frac{M}{d} \cdot D\right) \cdot \frac{h}{\ell}\right)}} \]
    5. Taylor expanded in M around 0 19.3

      \[\leadsto w0 \cdot \sqrt{1 - \frac{\frac{M}{d}}{\frac{4}{D}} \cdot \color{blue}{\frac{D \cdot \left(h \cdot M\right)}{\ell \cdot d}}} \]
    6. Simplified11.9

      \[\leadsto w0 \cdot \sqrt{1 - \frac{\frac{M}{d}}{\frac{4}{D}} \cdot \color{blue}{\left(\frac{h}{\ell} \cdot \frac{D}{\frac{d}{M}}\right)}} \]
      Proof
      (*.f64 w0 (sqrt.f64 (-.f64 1 (*.f64 (/.f64 (/.f64 M d) (/.f64 4 D)) (*.f64 (/.f64 h l) (/.f64 D (/.f64 d M))))))): 0 points increase in error, 0 points decrease in error
      (*.f64 w0 (sqrt.f64 (-.f64 1 (*.f64 (/.f64 (/.f64 M d) (/.f64 4 D)) (*.f64 (/.f64 h l) (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 D M) d))))))): 0 points increase in error, 0 points decrease in error
      (*.f64 w0 (sqrt.f64 (-.f64 1 (*.f64 (/.f64 (/.f64 M d) (/.f64 4 D)) (*.f64 (/.f64 h l) (/.f64 (Rewrite=> *-commutative_binary64 (*.f64 M D)) d)))))): 0 points increase in error, 0 points decrease in error
      (*.f64 w0 (sqrt.f64 (-.f64 1 (*.f64 (/.f64 (/.f64 M d) (/.f64 4 D)) (Rewrite<= times-frac_binary64 (/.f64 (*.f64 h (*.f64 M D)) (*.f64 l d))))))): 0 points increase in error, 0 points decrease in error
      (*.f64 w0 (sqrt.f64 (-.f64 1 (*.f64 (/.f64 (/.f64 M d) (/.f64 4 D)) (/.f64 (Rewrite=> associate-*r*_binary64 (*.f64 (*.f64 h M) D)) (*.f64 l d)))))): 0 points increase in error, 0 points decrease in error
      (*.f64 w0 (sqrt.f64 (-.f64 1 (*.f64 (/.f64 (/.f64 M d) (/.f64 4 D)) (/.f64 (Rewrite<= *-commutative_binary64 (*.f64 D (*.f64 h M))) (*.f64 l d)))))): 0 points increase in error, 0 points decrease in error

    if -4.9999999999999998e-303 < (/.f64 h l)

    1. Initial program 8.0

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

      \[\leadsto \color{blue}{w0 \cdot \sqrt{1 - {\left(D \cdot \frac{M}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}}} \]
      Proof
      (*.f64 w0 (sqrt.f64 (-.f64 1 (*.f64 (pow.f64 (*.f64 (/.f64 M 2) (/.f64 D d)) 2) (/.f64 h l))))): 0 points increase in error, 0 points decrease in error
      (*.f64 w0 (sqrt.f64 (-.f64 1 (*.f64 (pow.f64 (Rewrite<= times-frac_binary64 (/.f64 (*.f64 M D) (*.f64 2 d))) 2) (/.f64 h l))))): 1 points increase in error, 0 points decrease in error
    3. Taylor expanded in D around 0 3.2

      \[\leadsto \color{blue}{w0} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification8.6

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

Alternatives

Alternative 1
Error8.6
Cost14084
\[\begin{array}{l} \mathbf{if}\;\frac{h}{\ell} \leq -4 \cdot 10^{+264}:\\ \;\;\;\;w0 \cdot \sqrt{1 - \frac{h \cdot {\left(\frac{D}{d} \cdot \left(M \cdot 0.5\right)\right)}^{2}}{\ell}}\\ \mathbf{elif}\;\frac{h}{\ell} \leq -5 \cdot 10^{-303}:\\ \;\;\;\;w0 \cdot \sqrt{1 - \frac{\frac{M}{d}}{\frac{4}{D}} \cdot \left(\frac{h}{\ell} \cdot \frac{D}{\frac{d}{M}}\right)}\\ \mathbf{else}:\\ \;\;\;\;w0\\ \end{array} \]
Alternative 2
Error13.6
Cost8272
\[\begin{array}{l} \mathbf{if}\;d \leq -2 \cdot 10^{+38}:\\ \;\;\;\;w0 \cdot \left(1 + \left(\frac{M \cdot D}{d} \cdot \left(h \cdot \frac{M \cdot D}{\ell \cdot d}\right)\right) \cdot -0.125\right)\\ \mathbf{elif}\;d \leq -4 \cdot 10^{-114}:\\ \;\;\;\;w0 \cdot \sqrt{1 + \frac{D \cdot \left(D \cdot \left(M \cdot \left(h \cdot M\right)\right)\right)}{\ell} \cdot \frac{-0.25}{d \cdot d}}\\ \mathbf{elif}\;d \leq 1.18 \cdot 10^{-113}:\\ \;\;\;\;w0\\ \mathbf{elif}\;d \leq 2 \cdot 10^{+31}:\\ \;\;\;\;w0 \cdot \sqrt{1 - \left(M \cdot D\right) \cdot \frac{M \cdot D}{\left(4 \cdot \frac{\ell}{h}\right) \cdot \left(d \cdot d\right)}}\\ \mathbf{else}:\\ \;\;\;\;w0\\ \end{array} \]
Alternative 3
Error8.9
Cost8264
\[\begin{array}{l} t_0 := \frac{\frac{M}{d}}{\frac{4}{D}}\\ \mathbf{if}\;\frac{h}{\ell} \leq -\infty:\\ \;\;\;\;w0 \cdot \sqrt{1 - t_0 \cdot \left(h \cdot \frac{D}{d \cdot \frac{\ell}{M}}\right)}\\ \mathbf{elif}\;\frac{h}{\ell} \leq -5 \cdot 10^{-303}:\\ \;\;\;\;w0 \cdot \sqrt{1 - t_0 \cdot \left(\frac{h}{\ell} \cdot \left(D \cdot \frac{M}{d}\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;w0\\ \end{array} \]
Alternative 4
Error12.8
Cost8140
\[\begin{array}{l} \mathbf{if}\;d \leq -2.3 \cdot 10^{-114}:\\ \;\;\;\;w0 \cdot \sqrt{1 - \frac{\frac{M}{d}}{\frac{4}{D}} \cdot \left(h \cdot \frac{D}{d \cdot \frac{\ell}{M}}\right)}\\ \mathbf{elif}\;d \leq 4.6 \cdot 10^{-114}:\\ \;\;\;\;w0\\ \mathbf{elif}\;d \leq 1.3 \cdot 10^{+29}:\\ \;\;\;\;w0 \cdot \sqrt{1 - \left(M \cdot D\right) \cdot \frac{M \cdot D}{\left(4 \cdot \frac{\ell}{h}\right) \cdot \left(d \cdot d\right)}}\\ \mathbf{else}:\\ \;\;\;\;w0\\ \end{array} \]
Alternative 5
Error13.8
Cost8008
\[\begin{array}{l} \mathbf{if}\;d \leq -5 \cdot 10^{+40}:\\ \;\;\;\;w0 \cdot \left(1 + \left(\frac{M \cdot D}{d} \cdot \left(h \cdot \frac{M \cdot D}{\ell \cdot d}\right)\right) \cdot -0.125\right)\\ \mathbf{elif}\;d \leq -2.6 \cdot 10^{-114}:\\ \;\;\;\;w0 \cdot \sqrt{1 + \frac{D \cdot \left(D \cdot \left(M \cdot \left(h \cdot M\right)\right)\right)}{\ell} \cdot \frac{-0.25}{d \cdot d}}\\ \mathbf{else}:\\ \;\;\;\;w0\\ \end{array} \]
Alternative 6
Error13.7
Cost64
\[w0 \]

Error

Reproduce

herbie shell --seed 2022343 
(FPCore (w0 M D h l d)
  :name "Henrywood and Agarwal, Equation (9a)"
  :precision binary64
  (* w0 (sqrt (- 1.0 (* (pow (/ (* M D) (* 2.0 d)) 2.0) (/ h l))))))