Henrywood and Agarwal, Equation (9a)

Percentage Accurate: 81.2% → 93.0%
Time: 15.5s
Alternatives: 3
Speedup: 0.9×

Specification

?
\[\begin{array}{l} \\ w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \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))))))
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))));
}
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
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))));
}
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))))
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 tmp = code(w0, M, D, h, l, d)
	tmp = w0 * sqrt((1.0 - ((((M * D) / (2.0 * d)) ^ 2.0) * (h / l))));
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]
\begin{array}{l}

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 3 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 81.2% accurate, 1.0× speedup?

\[\begin{array}{l} \\ w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \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))))))
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))));
}
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
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))));
}
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))))
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 tmp = code(w0, M, D, h, l, d)
	tmp = w0 * sqrt((1.0 - ((((M * D) / (2.0 * d)) ^ 2.0) * (h / l))));
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]
\begin{array}{l}

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

Alternative 1: 93.0% accurate, 0.6× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ d_m = \left|d\right| \\ \begin{array}{l} t_0 := \frac{M\_m \cdot D\_m}{2 \cdot d\_m}\\ t_1 := {t\_0}^{2} \cdot \frac{h}{\ell}\\ \mathbf{if}\;t\_1 \leq -4 \cdot 10^{+297}:\\ \;\;\;\;\sqrt{\frac{h \cdot -0.25}{\ell}} \cdot \left(D\_m \cdot \frac{M\_m \cdot w0}{d\_m}\right)\\ \mathbf{elif}\;t\_1 \leq 1:\\ \;\;\;\;w0 \cdot \sqrt{1 - \frac{h}{\ell} \cdot \left(\frac{\left(M\_m \cdot D\_m\right) \cdot 0.5}{d\_m} \cdot t\_0\right)}\\ \mathbf{else}:\\ \;\;\;\;w0\\ \end{array} \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
d_m = (fabs.f64 d)
(FPCore (w0 M_m D_m h l d_m)
 :precision binary64
 (let* ((t_0 (/ (* M_m D_m) (* 2.0 d_m))) (t_1 (* (pow t_0 2.0) (/ h l))))
   (if (<= t_1 -4e+297)
     (* (sqrt (/ (* h -0.25) l)) (* D_m (/ (* M_m w0) d_m)))
     (if (<= t_1 1.0)
       (* w0 (sqrt (- 1.0 (* (/ h l) (* (/ (* (* M_m D_m) 0.5) d_m) t_0)))))
       w0))))
M_m = fabs(M);
D_m = fabs(D);
d_m = fabs(d);
double code(double w0, double M_m, double D_m, double h, double l, double d_m) {
	double t_0 = (M_m * D_m) / (2.0 * d_m);
	double t_1 = pow(t_0, 2.0) * (h / l);
	double tmp;
	if (t_1 <= -4e+297) {
		tmp = sqrt(((h * -0.25) / l)) * (D_m * ((M_m * w0) / d_m));
	} else if (t_1 <= 1.0) {
		tmp = w0 * sqrt((1.0 - ((h / l) * ((((M_m * D_m) * 0.5) / d_m) * t_0))));
	} else {
		tmp = w0;
	}
	return tmp;
}
M_m = abs(m)
D_m = abs(d)
d_m = abs(d)
real(8) function code(w0, m_m, d_m, h, l, d_m_1)
    real(8), intent (in) :: w0
    real(8), intent (in) :: m_m
    real(8), intent (in) :: d_m
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: d_m_1
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = (m_m * d_m) / (2.0d0 * d_m_1)
    t_1 = (t_0 ** 2.0d0) * (h / l)
    if (t_1 <= (-4d+297)) then
        tmp = sqrt(((h * (-0.25d0)) / l)) * (d_m * ((m_m * w0) / d_m_1))
    else if (t_1 <= 1.0d0) then
        tmp = w0 * sqrt((1.0d0 - ((h / l) * ((((m_m * d_m) * 0.5d0) / d_m_1) * t_0))))
    else
        tmp = w0
    end if
    code = tmp
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
d_m = Math.abs(d);
public static double code(double w0, double M_m, double D_m, double h, double l, double d_m) {
	double t_0 = (M_m * D_m) / (2.0 * d_m);
	double t_1 = Math.pow(t_0, 2.0) * (h / l);
	double tmp;
	if (t_1 <= -4e+297) {
		tmp = Math.sqrt(((h * -0.25) / l)) * (D_m * ((M_m * w0) / d_m));
	} else if (t_1 <= 1.0) {
		tmp = w0 * Math.sqrt((1.0 - ((h / l) * ((((M_m * D_m) * 0.5) / d_m) * t_0))));
	} else {
		tmp = w0;
	}
	return tmp;
}
M_m = math.fabs(M)
D_m = math.fabs(D)
d_m = math.fabs(d)
def code(w0, M_m, D_m, h, l, d_m):
	t_0 = (M_m * D_m) / (2.0 * d_m)
	t_1 = math.pow(t_0, 2.0) * (h / l)
	tmp = 0
	if t_1 <= -4e+297:
		tmp = math.sqrt(((h * -0.25) / l)) * (D_m * ((M_m * w0) / d_m))
	elif t_1 <= 1.0:
		tmp = w0 * math.sqrt((1.0 - ((h / l) * ((((M_m * D_m) * 0.5) / d_m) * t_0))))
	else:
		tmp = w0
	return tmp
M_m = abs(M)
D_m = abs(D)
d_m = abs(d)
function code(w0, M_m, D_m, h, l, d_m)
	t_0 = Float64(Float64(M_m * D_m) / Float64(2.0 * d_m))
	t_1 = Float64((t_0 ^ 2.0) * Float64(h / l))
	tmp = 0.0
	if (t_1 <= -4e+297)
		tmp = Float64(sqrt(Float64(Float64(h * -0.25) / l)) * Float64(D_m * Float64(Float64(M_m * w0) / d_m)));
	elseif (t_1 <= 1.0)
		tmp = Float64(w0 * sqrt(Float64(1.0 - Float64(Float64(h / l) * Float64(Float64(Float64(Float64(M_m * D_m) * 0.5) / d_m) * t_0)))));
	else
		tmp = w0;
	end
	return tmp
end
M_m = abs(M);
D_m = abs(D);
d_m = abs(d);
function tmp_2 = code(w0, M_m, D_m, h, l, d_m)
	t_0 = (M_m * D_m) / (2.0 * d_m);
	t_1 = (t_0 ^ 2.0) * (h / l);
	tmp = 0.0;
	if (t_1 <= -4e+297)
		tmp = sqrt(((h * -0.25) / l)) * (D_m * ((M_m * w0) / d_m));
	elseif (t_1 <= 1.0)
		tmp = w0 * sqrt((1.0 - ((h / l) * ((((M_m * D_m) * 0.5) / d_m) * t_0))));
	else
		tmp = w0;
	end
	tmp_2 = tmp;
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
d_m = N[Abs[d], $MachinePrecision]
code[w0_, M$95$m_, D$95$m_, h_, l_, d$95$m_] := Block[{t$95$0 = N[(N[(M$95$m * D$95$m), $MachinePrecision] / N[(2.0 * d$95$m), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Power[t$95$0, 2.0], $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -4e+297], N[(N[Sqrt[N[(N[(h * -0.25), $MachinePrecision] / l), $MachinePrecision]], $MachinePrecision] * N[(D$95$m * N[(N[(M$95$m * w0), $MachinePrecision] / d$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 1.0], N[(w0 * N[Sqrt[N[(1.0 - N[(N[(h / l), $MachinePrecision] * N[(N[(N[(N[(M$95$m * D$95$m), $MachinePrecision] * 0.5), $MachinePrecision] / d$95$m), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], w0]]]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
d_m = \left|d\right|

\\
\begin{array}{l}
t_0 := \frac{M\_m \cdot D\_m}{2 \cdot d\_m}\\
t_1 := {t\_0}^{2} \cdot \frac{h}{\ell}\\
\mathbf{if}\;t\_1 \leq -4 \cdot 10^{+297}:\\
\;\;\;\;\sqrt{\frac{h \cdot -0.25}{\ell}} \cdot \left(D\_m \cdot \frac{M\_m \cdot w0}{d\_m}\right)\\

\mathbf{elif}\;t\_1 \leq 1:\\
\;\;\;\;w0 \cdot \sqrt{1 - \frac{h}{\ell} \cdot \left(\frac{\left(M\_m \cdot D\_m\right) \cdot 0.5}{d\_m} \cdot t\_0\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) #s(literal 2 binary64)) (/.f64 h l)) < -4.0000000000000001e297

    1. Initial program 57.6%

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

      \[\leadsto \color{blue}{w0 \cdot \sqrt{1 - {\left(M \cdot \frac{D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}}} \]
    3. Add Preprocessing
    4. Step-by-step derivation
      1. clear-num57.6%

        \[\leadsto w0 \cdot \sqrt{1 - {\left(M \cdot \color{blue}{\frac{1}{\frac{2 \cdot d}{D}}}\right)}^{2} \cdot \frac{h}{\ell}} \]
      2. un-div-inv57.6%

        \[\leadsto w0 \cdot \sqrt{1 - {\color{blue}{\left(\frac{M}{\frac{2 \cdot d}{D}}\right)}}^{2} \cdot \frac{h}{\ell}} \]
      3. associate-/l*57.6%

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

      \[\leadsto w0 \cdot \sqrt{1 - {\color{blue}{\left(\frac{M}{2 \cdot \frac{d}{D}}\right)}}^{2} \cdot \frac{h}{\ell}} \]
    6. Step-by-step derivation
      1. associate-*r/59.1%

        \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\frac{{\left(\frac{M}{2 \cdot \frac{d}{D}}\right)}^{2} \cdot h}{\ell}}} \]
      2. associate-*r/59.1%

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

        \[\leadsto w0 \cdot \sqrt{1 - \frac{{\left(\frac{M}{\frac{\color{blue}{d \cdot 2}}{D}}\right)}^{2} \cdot h}{\ell}} \]
    7. Applied egg-rr59.1%

      \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\frac{{\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2} \cdot h}{\ell}}} \]
    8. Step-by-step derivation
      1. add-cube-cbrt59.1%

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

        \[\leadsto w0 \cdot \sqrt{1 - \frac{\color{blue}{{\left(\sqrt[3]{{\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2} \cdot h}\right)}^{3}}}{\ell}} \]
      3. associate-/r/59.1%

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(\frac{D \cdot \left(M \cdot \left(w0 \cdot {\left(\sqrt{-1}\right)}^{2}\right)\right)}{d} \cdot \sqrt{\frac{h \cdot {\left(\sqrt[3]{-0.25}\right)}^{3}}{\ell}}\right)} \]
    11. Step-by-step derivation
      1. mul-1-neg0.0%

        \[\leadsto \color{blue}{-\frac{D \cdot \left(M \cdot \left(w0 \cdot {\left(\sqrt{-1}\right)}^{2}\right)\right)}{d} \cdot \sqrt{\frac{h \cdot {\left(\sqrt[3]{-0.25}\right)}^{3}}{\ell}}} \]
      2. distribute-rgt-neg-in0.0%

        \[\leadsto \color{blue}{\frac{D \cdot \left(M \cdot \left(w0 \cdot {\left(\sqrt{-1}\right)}^{2}\right)\right)}{d} \cdot \left(-\sqrt{\frac{h \cdot {\left(\sqrt[3]{-0.25}\right)}^{3}}{\ell}}\right)} \]
      3. associate-/l*0.0%

        \[\leadsto \color{blue}{\left(D \cdot \frac{M \cdot \left(w0 \cdot {\left(\sqrt{-1}\right)}^{2}\right)}{d}\right)} \cdot \left(-\sqrt{\frac{h \cdot {\left(\sqrt[3]{-0.25}\right)}^{3}}{\ell}}\right) \]
      4. *-commutative0.0%

        \[\leadsto \left(D \cdot \frac{M \cdot \color{blue}{\left({\left(\sqrt{-1}\right)}^{2} \cdot w0\right)}}{d}\right) \cdot \left(-\sqrt{\frac{h \cdot {\left(\sqrt[3]{-0.25}\right)}^{3}}{\ell}}\right) \]
      5. unpow20.0%

        \[\leadsto \left(D \cdot \frac{M \cdot \left(\color{blue}{\left(\sqrt{-1} \cdot \sqrt{-1}\right)} \cdot w0\right)}{d}\right) \cdot \left(-\sqrt{\frac{h \cdot {\left(\sqrt[3]{-0.25}\right)}^{3}}{\ell}}\right) \]
      6. rem-square-sqrt51.1%

        \[\leadsto \left(D \cdot \frac{M \cdot \left(\color{blue}{-1} \cdot w0\right)}{d}\right) \cdot \left(-\sqrt{\frac{h \cdot {\left(\sqrt[3]{-0.25}\right)}^{3}}{\ell}}\right) \]
      7. mul-1-neg51.1%

        \[\leadsto \left(D \cdot \frac{M \cdot \color{blue}{\left(-w0\right)}}{d}\right) \cdot \left(-\sqrt{\frac{h \cdot {\left(\sqrt[3]{-0.25}\right)}^{3}}{\ell}}\right) \]
      8. rem-cube-cbrt51.1%

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

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

    if -4.0000000000000001e297 < (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) #s(literal 2 binary64)) (/.f64 h l)) < 1

    1. Initial program 99.9%

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

      \[\leadsto \color{blue}{w0 \cdot \sqrt{1 - {\left(M \cdot \frac{D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}}} \]
    3. Add Preprocessing
    4. Step-by-step derivation
      1. associate-*r/99.9%

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

        \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\left(\frac{M \cdot D}{2 \cdot d} \cdot \frac{M \cdot D}{2 \cdot d}\right)} \cdot \frac{h}{\ell}} \]
      3. associate-/r*99.9%

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

        \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\frac{\frac{M \cdot D}{2} \cdot \left(M \cdot D\right)}{d \cdot \left(2 \cdot d\right)}} \cdot \frac{h}{\ell}} \]
      5. associate-/l*79.9%

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

        \[\leadsto w0 \cdot \sqrt{1 - \frac{\left(M \cdot \color{blue}{\left(D \cdot \frac{1}{2}\right)}\right) \cdot \left(M \cdot D\right)}{d \cdot \left(2 \cdot d\right)} \cdot \frac{h}{\ell}} \]
      7. metadata-eval79.9%

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

      \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\frac{\left(M \cdot \left(D \cdot 0.5\right)\right) \cdot \left(M \cdot D\right)}{d \cdot \left(2 \cdot d\right)}} \cdot \frac{h}{\ell}} \]
    6. Step-by-step derivation
      1. times-frac99.9%

        \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\left(\frac{M \cdot \left(D \cdot 0.5\right)}{d} \cdot \frac{M \cdot D}{2 \cdot d}\right)} \cdot \frac{h}{\ell}} \]
      2. associate-*r*99.9%

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

        \[\leadsto w0 \cdot \sqrt{1 - \left(\frac{\left(M \cdot D\right) \cdot 0.5}{d} \cdot \frac{M \cdot D}{\color{blue}{d \cdot 2}}\right) \cdot \frac{h}{\ell}} \]
    7. Applied egg-rr99.9%

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

    if 1 < (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) #s(literal 2 binary64)) (/.f64 h l))

    1. Initial program 0.0%

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

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

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

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

Alternative 2: 90.7% accurate, 0.9× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ d_m = \left|d\right| \\ \begin{array}{l} \mathbf{if}\;{\left(\frac{M\_m \cdot D\_m}{2 \cdot d\_m}\right)}^{2} \cdot \frac{h}{\ell} \leq -4000:\\ \;\;\;\;w0 \cdot \left(\sqrt{\frac{h \cdot -0.25}{\ell}} \cdot \left(D\_m \cdot \frac{M\_m}{d\_m}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;w0\\ \end{array} \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
d_m = (fabs.f64 d)
(FPCore (w0 M_m D_m h l d_m)
 :precision binary64
 (if (<= (* (pow (/ (* M_m D_m) (* 2.0 d_m)) 2.0) (/ h l)) -4000.0)
   (* w0 (* (sqrt (/ (* h -0.25) l)) (* D_m (/ M_m d_m))))
   w0))
M_m = fabs(M);
D_m = fabs(D);
d_m = fabs(d);
double code(double w0, double M_m, double D_m, double h, double l, double d_m) {
	double tmp;
	if ((pow(((M_m * D_m) / (2.0 * d_m)), 2.0) * (h / l)) <= -4000.0) {
		tmp = w0 * (sqrt(((h * -0.25) / l)) * (D_m * (M_m / d_m)));
	} else {
		tmp = w0;
	}
	return tmp;
}
M_m = abs(m)
D_m = abs(d)
d_m = abs(d)
real(8) function code(w0, m_m, d_m, h, l, d_m_1)
    real(8), intent (in) :: w0
    real(8), intent (in) :: m_m
    real(8), intent (in) :: d_m
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: d_m_1
    real(8) :: tmp
    if (((((m_m * d_m) / (2.0d0 * d_m_1)) ** 2.0d0) * (h / l)) <= (-4000.0d0)) then
        tmp = w0 * (sqrt(((h * (-0.25d0)) / l)) * (d_m * (m_m / d_m_1)))
    else
        tmp = w0
    end if
    code = tmp
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
d_m = Math.abs(d);
public static double code(double w0, double M_m, double D_m, double h, double l, double d_m) {
	double tmp;
	if ((Math.pow(((M_m * D_m) / (2.0 * d_m)), 2.0) * (h / l)) <= -4000.0) {
		tmp = w0 * (Math.sqrt(((h * -0.25) / l)) * (D_m * (M_m / d_m)));
	} else {
		tmp = w0;
	}
	return tmp;
}
M_m = math.fabs(M)
D_m = math.fabs(D)
d_m = math.fabs(d)
def code(w0, M_m, D_m, h, l, d_m):
	tmp = 0
	if (math.pow(((M_m * D_m) / (2.0 * d_m)), 2.0) * (h / l)) <= -4000.0:
		tmp = w0 * (math.sqrt(((h * -0.25) / l)) * (D_m * (M_m / d_m)))
	else:
		tmp = w0
	return tmp
M_m = abs(M)
D_m = abs(D)
d_m = abs(d)
function code(w0, M_m, D_m, h, l, d_m)
	tmp = 0.0
	if (Float64((Float64(Float64(M_m * D_m) / Float64(2.0 * d_m)) ^ 2.0) * Float64(h / l)) <= -4000.0)
		tmp = Float64(w0 * Float64(sqrt(Float64(Float64(h * -0.25) / l)) * Float64(D_m * Float64(M_m / d_m))));
	else
		tmp = w0;
	end
	return tmp
end
M_m = abs(M);
D_m = abs(D);
d_m = abs(d);
function tmp_2 = code(w0, M_m, D_m, h, l, d_m)
	tmp = 0.0;
	if (((((M_m * D_m) / (2.0 * d_m)) ^ 2.0) * (h / l)) <= -4000.0)
		tmp = w0 * (sqrt(((h * -0.25) / l)) * (D_m * (M_m / d_m)));
	else
		tmp = w0;
	end
	tmp_2 = tmp;
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
d_m = N[Abs[d], $MachinePrecision]
code[w0_, M$95$m_, D$95$m_, h_, l_, d$95$m_] := If[LessEqual[N[(N[Power[N[(N[(M$95$m * D$95$m), $MachinePrecision] / N[(2.0 * d$95$m), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision], -4000.0], N[(w0 * N[(N[Sqrt[N[(N[(h * -0.25), $MachinePrecision] / l), $MachinePrecision]], $MachinePrecision] * N[(D$95$m * N[(M$95$m / d$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], w0]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
d_m = \left|d\right|

\\
\begin{array}{l}
\mathbf{if}\;{\left(\frac{M\_m \cdot D\_m}{2 \cdot d\_m}\right)}^{2} \cdot \frac{h}{\ell} \leq -4000:\\
\;\;\;\;w0 \cdot \left(\sqrt{\frac{h \cdot -0.25}{\ell}} \cdot \left(D\_m \cdot \frac{M\_m}{d\_m}\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) #s(literal 2 binary64)) (/.f64 h l)) < -4e3

    1. Initial program 65.8%

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

      \[\leadsto \color{blue}{w0 \cdot \sqrt{1 - {\left(M \cdot \frac{D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}}} \]
    3. Add Preprocessing
    4. Step-by-step derivation
      1. clear-num63.5%

        \[\leadsto w0 \cdot \sqrt{1 - {\left(M \cdot \color{blue}{\frac{1}{\frac{2 \cdot d}{D}}}\right)}^{2} \cdot \frac{h}{\ell}} \]
      2. un-div-inv63.5%

        \[\leadsto w0 \cdot \sqrt{1 - {\color{blue}{\left(\frac{M}{\frac{2 \cdot d}{D}}\right)}}^{2} \cdot \frac{h}{\ell}} \]
      3. associate-/l*63.5%

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

      \[\leadsto w0 \cdot \sqrt{1 - {\color{blue}{\left(\frac{M}{2 \cdot \frac{d}{D}}\right)}}^{2} \cdot \frac{h}{\ell}} \]
    6. Step-by-step derivation
      1. associate-*r/64.7%

        \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\frac{{\left(\frac{M}{2 \cdot \frac{d}{D}}\right)}^{2} \cdot h}{\ell}}} \]
      2. associate-*r/64.7%

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

        \[\leadsto w0 \cdot \sqrt{1 - \frac{{\left(\frac{M}{\frac{\color{blue}{d \cdot 2}}{D}}\right)}^{2} \cdot h}{\ell}} \]
    7. Applied egg-rr64.7%

      \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\frac{{\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2} \cdot h}{\ell}}} \]
    8. Step-by-step derivation
      1. add-cube-cbrt64.6%

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

        \[\leadsto w0 \cdot \sqrt{1 - \frac{\color{blue}{{\left(\sqrt[3]{{\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2} \cdot h}\right)}^{3}}}{\ell}} \]
      3. associate-/r/64.6%

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

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

      \[\leadsto w0 \cdot \color{blue}{\left(-1 \cdot \left(\frac{D \cdot \left(M \cdot {\left(\sqrt{-1}\right)}^{2}\right)}{d} \cdot \sqrt{\frac{h \cdot {\left(\sqrt[3]{-0.25}\right)}^{3}}{\ell}}\right)\right)} \]
    11. Step-by-step derivation
      1. mul-1-neg0.0%

        \[\leadsto w0 \cdot \color{blue}{\left(-\frac{D \cdot \left(M \cdot {\left(\sqrt{-1}\right)}^{2}\right)}{d} \cdot \sqrt{\frac{h \cdot {\left(\sqrt[3]{-0.25}\right)}^{3}}{\ell}}\right)} \]
      2. distribute-rgt-neg-in0.0%

        \[\leadsto w0 \cdot \color{blue}{\left(\frac{D \cdot \left(M \cdot {\left(\sqrt{-1}\right)}^{2}\right)}{d} \cdot \left(-\sqrt{\frac{h \cdot {\left(\sqrt[3]{-0.25}\right)}^{3}}{\ell}}\right)\right)} \]
      3. associate-/l*0.0%

        \[\leadsto w0 \cdot \left(\color{blue}{\left(D \cdot \frac{M \cdot {\left(\sqrt{-1}\right)}^{2}}{d}\right)} \cdot \left(-\sqrt{\frac{h \cdot {\left(\sqrt[3]{-0.25}\right)}^{3}}{\ell}}\right)\right) \]
      4. *-commutative0.0%

        \[\leadsto w0 \cdot \left(\left(D \cdot \frac{\color{blue}{{\left(\sqrt{-1}\right)}^{2} \cdot M}}{d}\right) \cdot \left(-\sqrt{\frac{h \cdot {\left(\sqrt[3]{-0.25}\right)}^{3}}{\ell}}\right)\right) \]
      5. unpow20.0%

        \[\leadsto w0 \cdot \left(\left(D \cdot \frac{\color{blue}{\left(\sqrt{-1} \cdot \sqrt{-1}\right)} \cdot M}{d}\right) \cdot \left(-\sqrt{\frac{h \cdot {\left(\sqrt[3]{-0.25}\right)}^{3}}{\ell}}\right)\right) \]
      6. rem-square-sqrt43.0%

        \[\leadsto w0 \cdot \left(\left(D \cdot \frac{\color{blue}{-1} \cdot M}{d}\right) \cdot \left(-\sqrt{\frac{h \cdot {\left(\sqrt[3]{-0.25}\right)}^{3}}{\ell}}\right)\right) \]
      7. mul-1-neg43.0%

        \[\leadsto w0 \cdot \left(\left(D \cdot \frac{\color{blue}{-M}}{d}\right) \cdot \left(-\sqrt{\frac{h \cdot {\left(\sqrt[3]{-0.25}\right)}^{3}}{\ell}}\right)\right) \]
      8. rem-cube-cbrt43.0%

        \[\leadsto w0 \cdot \left(\left(D \cdot \frac{-M}{d}\right) \cdot \left(-\sqrt{\frac{h \cdot \color{blue}{-0.25}}{\ell}}\right)\right) \]
    12. Simplified43.0%

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

    if -4e3 < (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) #s(literal 2 binary64)) (/.f64 h l))

    1. Initial program 85.1%

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

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

      \[\leadsto \color{blue}{w0} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification78.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell} \leq -4000:\\ \;\;\;\;w0 \cdot \left(\sqrt{\frac{h \cdot -0.25}{\ell}} \cdot \left(D \cdot \frac{M}{d}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;w0\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 68.0% accurate, 216.0× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ d_m = \left|d\right| \\ w0 \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
d_m = (fabs.f64 d)
(FPCore (w0 M_m D_m h l d_m) :precision binary64 w0)
M_m = fabs(M);
D_m = fabs(D);
d_m = fabs(d);
double code(double w0, double M_m, double D_m, double h, double l, double d_m) {
	return w0;
}
M_m = abs(m)
D_m = abs(d)
d_m = abs(d)
real(8) function code(w0, m_m, d_m, h, l, d_m_1)
    real(8), intent (in) :: w0
    real(8), intent (in) :: m_m
    real(8), intent (in) :: d_m
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: d_m_1
    code = w0
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
d_m = Math.abs(d);
public static double code(double w0, double M_m, double D_m, double h, double l, double d_m) {
	return w0;
}
M_m = math.fabs(M)
D_m = math.fabs(D)
d_m = math.fabs(d)
def code(w0, M_m, D_m, h, l, d_m):
	return w0
M_m = abs(M)
D_m = abs(D)
d_m = abs(d)
function code(w0, M_m, D_m, h, l, d_m)
	return w0
end
M_m = abs(M);
D_m = abs(D);
d_m = abs(d);
function tmp = code(w0, M_m, D_m, h, l, d_m)
	tmp = w0;
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
d_m = N[Abs[d], $MachinePrecision]
code[w0_, M$95$m_, D$95$m_, h_, l_, d$95$m_] := w0
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
d_m = \left|d\right|

\\
w0
\end{array}
Derivation
  1. Initial program 79.0%

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

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

    \[\leadsto \color{blue}{w0} \]
  5. Add Preprocessing

Reproduce

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