Average Error: 13.8 → 8.9
Time: 16.2s
Precision: binary64
Cost: 8264
\[ \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} t_0 := \frac{D}{d} \cdot M\\ \mathbf{if}\;\frac{h}{\ell} \leq -4 \cdot 10^{+290}:\\ \;\;\;\;w0\\ \mathbf{elif}\;\frac{h}{\ell} \leq -2 \cdot 10^{-209}:\\ \;\;\;\;w0 \cdot \sqrt{1 - \left(t_0 \cdot 0.25\right) \cdot \left(\frac{h}{\ell} \cdot t_0\right)}\\ \mathbf{else}:\\ \;\;\;\;w0 \cdot \sqrt{1 - \left(h \cdot \frac{D \cdot \frac{M}{d}}{\ell}\right) \cdot \frac{\frac{D}{\frac{d}{M}}}{4}}\\ \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
 (let* ((t_0 (* (/ D d) M)))
   (if (<= (/ h l) -4e+290)
     w0
     (if (<= (/ h l) -2e-209)
       (* w0 (sqrt (- 1.0 (* (* t_0 0.25) (* (/ h l) t_0)))))
       (*
        w0
        (sqrt (- 1.0 (* (* h (/ (* D (/ M d)) l)) (/ (/ D (/ d M)) 4.0)))))))))
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 t_0 = (D / d) * M;
	double tmp;
	if ((h / l) <= -4e+290) {
		tmp = w0;
	} else if ((h / l) <= -2e-209) {
		tmp = w0 * sqrt((1.0 - ((t_0 * 0.25) * ((h / l) * t_0))));
	} else {
		tmp = w0 * sqrt((1.0 - ((h * ((D * (M / d)) / l)) * ((D / (d / M)) / 4.0))));
	}
	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) :: t_0
    real(8) :: tmp
    t_0 = (d / d_1) * m
    if ((h / l) <= (-4d+290)) then
        tmp = w0
    else if ((h / l) <= (-2d-209)) then
        tmp = w0 * sqrt((1.0d0 - ((t_0 * 0.25d0) * ((h / l) * t_0))))
    else
        tmp = w0 * sqrt((1.0d0 - ((h * ((d * (m / d_1)) / l)) * ((d / (d_1 / m)) / 4.0d0))))
    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 t_0 = (D / d) * M;
	double tmp;
	if ((h / l) <= -4e+290) {
		tmp = w0;
	} else if ((h / l) <= -2e-209) {
		tmp = w0 * Math.sqrt((1.0 - ((t_0 * 0.25) * ((h / l) * t_0))));
	} else {
		tmp = w0 * Math.sqrt((1.0 - ((h * ((D * (M / d)) / l)) * ((D / (d / M)) / 4.0))));
	}
	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):
	t_0 = (D / d) * M
	tmp = 0
	if (h / l) <= -4e+290:
		tmp = w0
	elif (h / l) <= -2e-209:
		tmp = w0 * math.sqrt((1.0 - ((t_0 * 0.25) * ((h / l) * t_0))))
	else:
		tmp = w0 * math.sqrt((1.0 - ((h * ((D * (M / d)) / l)) * ((D / (d / M)) / 4.0))))
	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)
	t_0 = Float64(Float64(D / d) * M)
	tmp = 0.0
	if (Float64(h / l) <= -4e+290)
		tmp = w0;
	elseif (Float64(h / l) <= -2e-209)
		tmp = Float64(w0 * sqrt(Float64(1.0 - Float64(Float64(t_0 * 0.25) * Float64(Float64(h / l) * t_0)))));
	else
		tmp = Float64(w0 * sqrt(Float64(1.0 - Float64(Float64(h * Float64(Float64(D * Float64(M / d)) / l)) * Float64(Float64(D / Float64(d / M)) / 4.0)))));
	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)
	t_0 = (D / d) * M;
	tmp = 0.0;
	if ((h / l) <= -4e+290)
		tmp = w0;
	elseif ((h / l) <= -2e-209)
		tmp = w0 * sqrt((1.0 - ((t_0 * 0.25) * ((h / l) * t_0))));
	else
		tmp = w0 * sqrt((1.0 - ((h * ((D * (M / d)) / l)) * ((D / (d / M)) / 4.0))));
	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_] := Block[{t$95$0 = N[(N[(D / d), $MachinePrecision] * M), $MachinePrecision]}, If[LessEqual[N[(h / l), $MachinePrecision], -4e+290], w0, If[LessEqual[N[(h / l), $MachinePrecision], -2e-209], N[(w0 * N[Sqrt[N[(1.0 - N[(N[(t$95$0 * 0.25), $MachinePrecision] * N[(N[(h / l), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(w0 * N[Sqrt[N[(1.0 - N[(N[(h * N[(N[(D * N[(M / d), $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision] * N[(N[(D / N[(d / M), $MachinePrecision]), $MachinePrecision] / 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]
w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}}
\begin{array}{l}
t_0 := \frac{D}{d} \cdot M\\
\mathbf{if}\;\frac{h}{\ell} \leq -4 \cdot 10^{+290}:\\
\;\;\;\;w0\\

\mathbf{elif}\;\frac{h}{\ell} \leq -2 \cdot 10^{-209}:\\
\;\;\;\;w0 \cdot \sqrt{1 - \left(t_0 \cdot 0.25\right) \cdot \left(\frac{h}{\ell} \cdot t_0\right)}\\

\mathbf{else}:\\
\;\;\;\;w0 \cdot \sqrt{1 - \left(h \cdot \frac{D \cdot \frac{M}{d}}{\ell}\right) \cdot \frac{\frac{D}{\frac{d}{M}}}{4}}\\


\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.00000000000000025e290

    1. Initial program 59.6

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

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

      [Start]59.6

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

      associate-*l/ [<=]59.4

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

      *-commutative [=>]59.4

      \[ w0 \cdot \sqrt{1 - {\color{blue}{\left(D \cdot \frac{M}{2 \cdot d}\right)}}^{2} \cdot \frac{h}{\ell}} \]
    3. Taylor expanded in D around 0 35.8

      \[\leadsto \color{blue}{w0} \]

    if -4.00000000000000025e290 < (/.f64 h l) < -2.0000000000000001e-209

    1. Initial program 13.9

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

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

      [Start]13.9

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

      times-frac [=>]14.0

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

      \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\frac{\frac{M}{\frac{d}{D}} \cdot \frac{M}{\frac{d}{D}}}{\frac{\ell}{h} \cdot 4}}} \]
    4. Simplified13.5

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

      [Start]13.8

      \[ w0 \cdot \sqrt{1 - \frac{\frac{M}{\frac{d}{D}} \cdot \frac{M}{\frac{d}{D}}}{\frac{\ell}{h} \cdot 4}} \]

      times-frac [=>]12.6

      \[ w0 \cdot \sqrt{1 - \color{blue}{\frac{\frac{M}{\frac{d}{D}}}{\frac{\ell}{h}} \cdot \frac{\frac{M}{\frac{d}{D}}}{4}}} \]

      associate-/r/ [=>]13.3

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

      associate-/r/ [=>]14.2

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

      *-commutative [=>]14.2

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

      associate-/r/ [=>]13.5

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

      *-commutative [=>]13.5

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

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(w0 \cdot \sqrt{1 - \left(D \cdot \frac{M}{d}\right) \cdot \left(0.25 \cdot \left(\frac{D}{\ell \cdot \frac{d}{M}} \cdot h\right)\right)}\right)} - 1} \]
    6. Simplified12.7

      \[\leadsto \color{blue}{w0 \cdot \sqrt{1 - \left(\left(\frac{D}{d} \cdot M\right) \cdot 0.25\right) \cdot \left(\frac{h}{\ell} \cdot \left(\frac{D}{d} \cdot M\right)\right)}} \]
      Proof

      [Start]51.1

      \[ e^{\mathsf{log1p}\left(w0 \cdot \sqrt{1 - \left(D \cdot \frac{M}{d}\right) \cdot \left(0.25 \cdot \left(\frac{D}{\ell \cdot \frac{d}{M}} \cdot h\right)\right)}\right)} - 1 \]

      expm1-def [=>]29.1

      \[ \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(w0 \cdot \sqrt{1 - \left(D \cdot \frac{M}{d}\right) \cdot \left(0.25 \cdot \left(\frac{D}{\ell \cdot \frac{d}{M}} \cdot h\right)\right)}\right)\right)} \]

      expm1-log1p [=>]15.8

      \[ \color{blue}{w0 \cdot \sqrt{1 - \left(D \cdot \frac{M}{d}\right) \cdot \left(0.25 \cdot \left(\frac{D}{\ell \cdot \frac{d}{M}} \cdot h\right)\right)}} \]

      associate-*r* [=>]15.8

      \[ w0 \cdot \sqrt{1 - \color{blue}{\left(\left(D \cdot \frac{M}{d}\right) \cdot 0.25\right) \cdot \left(\frac{D}{\ell \cdot \frac{d}{M}} \cdot h\right)}} \]

      associate-*r/ [=>]16.3

      \[ w0 \cdot \sqrt{1 - \left(\color{blue}{\frac{D \cdot M}{d}} \cdot 0.25\right) \cdot \left(\frac{D}{\ell \cdot \frac{d}{M}} \cdot h\right)} \]

      associate-*l/ [<=]16.3

      \[ w0 \cdot \sqrt{1 - \left(\color{blue}{\left(\frac{D}{d} \cdot M\right)} \cdot 0.25\right) \cdot \left(\frac{D}{\ell \cdot \frac{d}{M}} \cdot h\right)} \]

      associate-*l/ [=>]18.6

      \[ w0 \cdot \sqrt{1 - \left(\left(\frac{D}{d} \cdot M\right) \cdot 0.25\right) \cdot \color{blue}{\frac{D \cdot h}{\ell \cdot \frac{d}{M}}}} \]

      *-commutative [<=]18.6

      \[ w0 \cdot \sqrt{1 - \left(\left(\frac{D}{d} \cdot M\right) \cdot 0.25\right) \cdot \frac{\color{blue}{h \cdot D}}{\ell \cdot \frac{d}{M}}} \]

      times-frac [=>]13.5

      \[ w0 \cdot \sqrt{1 - \left(\left(\frac{D}{d} \cdot M\right) \cdot 0.25\right) \cdot \color{blue}{\left(\frac{h}{\ell} \cdot \frac{D}{\frac{d}{M}}\right)}} \]

      associate-/r/ [=>]12.7

      \[ w0 \cdot \sqrt{1 - \left(\left(\frac{D}{d} \cdot M\right) \cdot 0.25\right) \cdot \left(\frac{h}{\ell} \cdot \color{blue}{\left(\frac{D}{d} \cdot M\right)}\right)} \]

    if -2.0000000000000001e-209 < (/.f64 h l)

    1. Initial program 8.7

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

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

      [Start]8.7

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

      times-frac [=>]8.9

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

      \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\frac{\frac{M}{\frac{d}{D}} \cdot \frac{M}{\frac{d}{D}}}{\frac{\ell}{h} \cdot 4}}} \]
    4. Simplified3.2

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

      [Start]8.5

      \[ w0 \cdot \sqrt{1 - \frac{\frac{M}{\frac{d}{D}} \cdot \frac{M}{\frac{d}{D}}}{\frac{\ell}{h} \cdot 4}} \]

      times-frac [=>]6.8

      \[ w0 \cdot \sqrt{1 - \color{blue}{\frac{\frac{M}{\frac{d}{D}}}{\frac{\ell}{h}} \cdot \frac{\frac{M}{\frac{d}{D}}}{4}}} \]

      associate-/r/ [=>]3.2

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

      associate-/r/ [=>]4.2

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

      *-commutative [=>]4.2

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

      associate-/r/ [=>]3.2

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

      *-commutative [=>]3.2

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

      \[\leadsto w0 \cdot \sqrt{1 - \left(\frac{D \cdot \frac{M}{d}}{\ell} \cdot h\right) \cdot \frac{\color{blue}{\frac{D}{\frac{d}{M}}}}{4}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification8.9

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

Alternatives

Alternative 1
Error8.9
Cost8264
\[\begin{array}{l} t_0 := D \cdot \frac{M}{d}\\ t_1 := \frac{D}{d} \cdot M\\ \mathbf{if}\;\frac{h}{\ell} \leq -4 \cdot 10^{+290}:\\ \;\;\;\;w0\\ \mathbf{elif}\;\frac{h}{\ell} \leq -2 \cdot 10^{-209}:\\ \;\;\;\;w0 \cdot \sqrt{1 - \left(t_1 \cdot 0.25\right) \cdot \left(\frac{h}{\ell} \cdot t_1\right)}\\ \mathbf{else}:\\ \;\;\;\;w0 \cdot \sqrt{1 - \left(h \cdot \frac{t_0}{\ell}\right) \cdot \frac{t_0}{4}}\\ \end{array} \]
Alternative 2
Error11.1
Cost8004
\[\begin{array}{l} t_0 := \frac{D}{d} \cdot M\\ \mathbf{if}\;\frac{h}{\ell} \leq -4 \cdot 10^{+290}:\\ \;\;\;\;w0\\ \mathbf{else}:\\ \;\;\;\;w0 \cdot \sqrt{1 - \left(t_0 \cdot 0.25\right) \cdot \left(\frac{h}{\ell} \cdot t_0\right)}\\ \end{array} \]
Alternative 3
Error13.9
Cost64
\[w0 \]

Error

Reproduce

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