Henrywood and Agarwal, Equation (9a)

Percentage Accurate: 81.3% → 81.3%
Time: 3.2s
Alternatives: 7
Speedup: 1.0×

Specification

?
\[\mathsf{TRUE}\left(\right)\]
\[\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 7 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.3% 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: 81.3% 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}
Derivation
  1. Initial program 78.7%

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

Alternative 2: 16.6% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}\\ t_1 := 1 - t\_0\\ \mathbf{if}\;w0 \cdot \sqrt{t\_1} \leq 5 \cdot 10^{-156}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (w0 M D h l d)
 :precision binary64
 (let* ((t_0 (* (pow (/ (* M D) (* 2.0 d)) 2.0) (/ h l))) (t_1 (- 1.0 t_0)))
   (if (<= (* w0 (sqrt t_1)) 5e-156) t_0 t_1)))
double code(double w0, double M, double D, double h, double l, double d) {
	double t_0 = pow(((M * D) / (2.0 * d)), 2.0) * (h / l);
	double t_1 = 1.0 - t_0;
	double tmp;
	if ((w0 * sqrt(t_1)) <= 5e-156) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	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
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = (((m * d) / (2.0d0 * d_1)) ** 2.0d0) * (h / l)
    t_1 = 1.0d0 - t_0
    if ((w0 * sqrt(t_1)) <= 5d-156) then
        tmp = t_0
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double w0, double M, double D, double h, double l, double d) {
	double t_0 = Math.pow(((M * D) / (2.0 * d)), 2.0) * (h / l);
	double t_1 = 1.0 - t_0;
	double tmp;
	if ((w0 * Math.sqrt(t_1)) <= 5e-156) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(w0, M, D, h, l, d):
	t_0 = math.pow(((M * D) / (2.0 * d)), 2.0) * (h / l)
	t_1 = 1.0 - t_0
	tmp = 0
	if (w0 * math.sqrt(t_1)) <= 5e-156:
		tmp = t_0
	else:
		tmp = t_1
	return tmp
function code(w0, M, D, h, l, d)
	t_0 = Float64((Float64(Float64(M * D) / Float64(2.0 * d)) ^ 2.0) * Float64(h / l))
	t_1 = Float64(1.0 - t_0)
	tmp = 0.0
	if (Float64(w0 * sqrt(t_1)) <= 5e-156)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(w0, M, D, h, l, d)
	t_0 = (((M * D) / (2.0 * d)) ^ 2.0) * (h / l);
	t_1 = 1.0 - t_0;
	tmp = 0.0;
	if ((w0 * sqrt(t_1)) <= 5e-156)
		tmp = t_0;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[w0_, M_, D_, h_, l_, d_] := Block[{t$95$0 = N[(N[Power[N[(N[(M * D), $MachinePrecision] / N[(2.0 * d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 - t$95$0), $MachinePrecision]}, If[LessEqual[N[(w0 * N[Sqrt[t$95$1], $MachinePrecision]), $MachinePrecision], 5e-156], t$95$0, t$95$1]]]
\begin{array}{l}

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

\mathbf{else}:\\
\;\;\;\;t\_1\\


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

    1. Initial program 91.0%

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

      \[\leadsto \color{blue}{w0 + {M}^{2} \cdot \left(\frac{-1}{8} \cdot \frac{{D}^{2} \cdot \left(h \cdot w0\right)}{{d}^{2} \cdot \ell} + \frac{-1}{128} \cdot \frac{{D}^{4} \cdot \left({M}^{2} \cdot \left({h}^{2} \cdot w0\right)\right)}{{d}^{4} \cdot {\ell}^{2}}\right)} \]
    4. Applied rewrites16.9%

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

    if 5.00000000000000007e-156 < (*.f64 w0 (sqrt.f64 (-.f64 #s(literal 1 binary64) (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) #s(literal 2 binary64)) (/.f64 h l)))))

    1. Initial program 64.3%

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

      \[\leadsto \color{blue}{w0 + \frac{-1}{8} \cdot \frac{{D}^{2} \cdot \left({M}^{2} \cdot \left(h \cdot w0\right)\right)}{{d}^{2} \cdot \ell}} \]
    4. Applied rewrites11.9%

      \[\leadsto \color{blue}{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 3: 15.9% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\\ t_1 := t\_0 \cdot \frac{h}{\ell}\\ \mathbf{if}\;w0 \cdot \sqrt{1 - t\_1} \leq 5 \cdot 10^{-282}:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (w0 M D h l d)
 :precision binary64
 (let* ((t_0 (pow (/ (* M D) (* 2.0 d)) 2.0)) (t_1 (* t_0 (/ h l))))
   (if (<= (* w0 (sqrt (- 1.0 t_1))) 5e-282) t_1 t_0)))
double code(double w0, double M, double D, double h, double l, double d) {
	double t_0 = pow(((M * D) / (2.0 * d)), 2.0);
	double t_1 = t_0 * (h / l);
	double tmp;
	if ((w0 * sqrt((1.0 - t_1))) <= 5e-282) {
		tmp = t_1;
	} else {
		tmp = t_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
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = ((m * d) / (2.0d0 * d_1)) ** 2.0d0
    t_1 = t_0 * (h / l)
    if ((w0 * sqrt((1.0d0 - t_1))) <= 5d-282) then
        tmp = t_1
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double w0, double M, double D, double h, double l, double d) {
	double t_0 = Math.pow(((M * D) / (2.0 * d)), 2.0);
	double t_1 = t_0 * (h / l);
	double tmp;
	if ((w0 * Math.sqrt((1.0 - t_1))) <= 5e-282) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(w0, M, D, h, l, d):
	t_0 = math.pow(((M * D) / (2.0 * d)), 2.0)
	t_1 = t_0 * (h / l)
	tmp = 0
	if (w0 * math.sqrt((1.0 - t_1))) <= 5e-282:
		tmp = t_1
	else:
		tmp = t_0
	return tmp
function code(w0, M, D, h, l, d)
	t_0 = Float64(Float64(M * D) / Float64(2.0 * d)) ^ 2.0
	t_1 = Float64(t_0 * Float64(h / l))
	tmp = 0.0
	if (Float64(w0 * sqrt(Float64(1.0 - t_1))) <= 5e-282)
		tmp = t_1;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(w0, M, D, h, l, d)
	t_0 = ((M * D) / (2.0 * d)) ^ 2.0;
	t_1 = t_0 * (h / l);
	tmp = 0.0;
	if ((w0 * sqrt((1.0 - t_1))) <= 5e-282)
		tmp = t_1;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[w0_, M_, D_, h_, l_, d_] := Block[{t$95$0 = N[Power[N[(N[(M * D), $MachinePrecision] / N[(2.0 * d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 * N[(h / l), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(w0 * N[Sqrt[N[(1.0 - t$95$1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 5e-282], t$95$1, t$95$0]]]
\begin{array}{l}

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

\mathbf{else}:\\
\;\;\;\;t\_0\\


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

    1. Initial program 89.7%

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

      \[\leadsto \color{blue}{w0 + {M}^{2} \cdot \left(\frac{-1}{8} \cdot \frac{{D}^{2} \cdot \left(h \cdot w0\right)}{{d}^{2} \cdot \ell} + \frac{-1}{128} \cdot \frac{{D}^{4} \cdot \left({M}^{2} \cdot \left({h}^{2} \cdot w0\right)\right)}{{d}^{4} \cdot {\ell}^{2}}\right)} \]
    4. Applied rewrites18.7%

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

    if 5.0000000000000001e-282 < (*.f64 w0 (sqrt.f64 (-.f64 #s(literal 1 binary64) (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) #s(literal 2 binary64)) (/.f64 h l)))))

    1. Initial program 69.0%

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

      \[\leadsto \color{blue}{w0} \]
    4. Applied rewrites10.8%

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

      \[\leadsto 1 \]
    6. Applied rewrites9.7%

      \[\leadsto {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{\color{blue}{2}} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 4: 11.3% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{M \cdot D}{2 \cdot d}\\ \mathbf{if}\;w0 \leq -1.95 \cdot 10^{-306}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;{t\_0}^{2}\\ \end{array} \end{array} \]
(FPCore (w0 M D h l d)
 :precision binary64
 (let* ((t_0 (/ (* M D) (* 2.0 d))))
   (if (<= w0 -1.95e-306) t_0 (pow t_0 2.0))))
double code(double w0, double M, double D, double h, double l, double d) {
	double t_0 = (M * D) / (2.0 * d);
	double tmp;
	if (w0 <= -1.95e-306) {
		tmp = t_0;
	} else {
		tmp = pow(t_0, 2.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
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (m * d) / (2.0d0 * d_1)
    if (w0 <= (-1.95d-306)) then
        tmp = t_0
    else
        tmp = t_0 ** 2.0d0
    end if
    code = tmp
end function
public static double code(double w0, double M, double D, double h, double l, double d) {
	double t_0 = (M * D) / (2.0 * d);
	double tmp;
	if (w0 <= -1.95e-306) {
		tmp = t_0;
	} else {
		tmp = Math.pow(t_0, 2.0);
	}
	return tmp;
}
def code(w0, M, D, h, l, d):
	t_0 = (M * D) / (2.0 * d)
	tmp = 0
	if w0 <= -1.95e-306:
		tmp = t_0
	else:
		tmp = math.pow(t_0, 2.0)
	return tmp
function code(w0, M, D, h, l, d)
	t_0 = Float64(Float64(M * D) / Float64(2.0 * d))
	tmp = 0.0
	if (w0 <= -1.95e-306)
		tmp = t_0;
	else
		tmp = t_0 ^ 2.0;
	end
	return tmp
end
function tmp_2 = code(w0, M, D, h, l, d)
	t_0 = (M * D) / (2.0 * d);
	tmp = 0.0;
	if (w0 <= -1.95e-306)
		tmp = t_0;
	else
		tmp = t_0 ^ 2.0;
	end
	tmp_2 = tmp;
end
code[w0_, M_, D_, h_, l_, d_] := Block[{t$95$0 = N[(N[(M * D), $MachinePrecision] / N[(2.0 * d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[w0, -1.95e-306], t$95$0, N[Power[t$95$0, 2.0], $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{M \cdot D}{2 \cdot d}\\
\mathbf{if}\;w0 \leq -1.95 \cdot 10^{-306}:\\
\;\;\;\;t\_0\\

\mathbf{else}:\\
\;\;\;\;{t\_0}^{2}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if w0 < -1.95e-306

    1. Initial program 79.7%

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

      \[\leadsto \color{blue}{w0 + {M}^{2} \cdot \left(\frac{-1}{8} \cdot \frac{{D}^{2} \cdot \left(h \cdot w0\right)}{{d}^{2} \cdot \ell} + {M}^{2} \cdot \left(\frac{-1}{128} \cdot \frac{{D}^{4} \cdot \left({h}^{2} \cdot w0\right)}{{d}^{4} \cdot {\ell}^{2}} + \frac{-1}{1024} \cdot \frac{{D}^{6} \cdot \left({M}^{2} \cdot \left({h}^{3} \cdot w0\right)\right)}{{d}^{6} \cdot {\ell}^{3}}\right)\right)} \]
    4. Applied rewrites10.2%

      \[\leadsto \color{blue}{\frac{M \cdot D}{2 \cdot d}} \]

    if -1.95e-306 < w0

    1. Initial program 77.7%

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

      \[\leadsto \color{blue}{w0} \]
    4. Applied rewrites11.7%

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

      \[\leadsto 1 \]
    6. Applied rewrites10.6%

      \[\leadsto {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{\color{blue}{2}} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 5: 7.5% accurate, 7.1× speedup?

\[\begin{array}{l} \\ \frac{M \cdot D}{2 \cdot d} \end{array} \]
(FPCore (w0 M D h l d) :precision binary64 (/ (* M D) (* 2.0 d)))
double code(double w0, double M, double D, double h, double l, double d) {
	return (M * D) / (2.0 * d);
}
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 = (m * d) / (2.0d0 * d_1)
end function
public static double code(double w0, double M, double D, double h, double l, double d) {
	return (M * D) / (2.0 * d);
}
def code(w0, M, D, h, l, d):
	return (M * D) / (2.0 * d)
function code(w0, M, D, h, l, d)
	return Float64(Float64(M * D) / Float64(2.0 * d))
end
function tmp = code(w0, M, D, h, l, d)
	tmp = (M * D) / (2.0 * d);
end
code[w0_, M_, D_, h_, l_, d_] := N[(N[(M * D), $MachinePrecision] / N[(2.0 * d), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{M \cdot D}{2 \cdot d}
\end{array}
Derivation
  1. Initial program 78.7%

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

    \[\leadsto \color{blue}{w0 + {M}^{2} \cdot \left(\frac{-1}{8} \cdot \frac{{D}^{2} \cdot \left(h \cdot w0\right)}{{d}^{2} \cdot \ell} + {M}^{2} \cdot \left(\frac{-1}{128} \cdot \frac{{D}^{4} \cdot \left({h}^{2} \cdot w0\right)}{{d}^{4} \cdot {\ell}^{2}} + \frac{-1}{1024} \cdot \frac{{D}^{6} \cdot \left({M}^{2} \cdot \left({h}^{3} \cdot w0\right)\right)}{{d}^{6} \cdot {\ell}^{3}}\right)\right)} \]
  4. Applied rewrites7.6%

    \[\leadsto \color{blue}{\frac{M \cdot D}{2 \cdot d}} \]
  5. Add Preprocessing

Alternative 6: 6.0% accurate, 26.2× speedup?

\[\begin{array}{l} \\ M \cdot D \end{array} \]
(FPCore (w0 M D h l d) :precision binary64 (* M D))
double code(double w0, double M, double D, double h, double l, double d) {
	return M * D;
}
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 = m * d
end function
public static double code(double w0, double M, double D, double h, double l, double d) {
	return M * D;
}
def code(w0, M, D, h, l, d):
	return M * D
function code(w0, M, D, h, l, d)
	return Float64(M * D)
end
function tmp = code(w0, M, D, h, l, d)
	tmp = M * D;
end
code[w0_, M_, D_, h_, l_, d_] := N[(M * D), $MachinePrecision]
\begin{array}{l}

\\
M \cdot D
\end{array}
Derivation
  1. Initial program 78.7%

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

    \[\leadsto \color{blue}{w0 + \frac{-1}{8} \cdot \frac{{D}^{2} \cdot \left({M}^{2} \cdot \left(h \cdot w0\right)\right)}{{d}^{2} \cdot \ell}} \]
  4. Applied rewrites6.4%

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

    \[\leadsto 1 + \color{blue}{\frac{-1}{4} \cdot \frac{{D}^{2} \cdot \left({M}^{2} \cdot h\right)}{{d}^{2} \cdot \ell}} \]
  6. Applied rewrites4.8%

    \[\leadsto M \cdot \color{blue}{D} \]
  7. Add Preprocessing

Alternative 7: 3.0% accurate, 26.2× speedup?

\[\begin{array}{l} \\ 2 \cdot d \end{array} \]
(FPCore (w0 M D h l d) :precision binary64 (* 2.0 d))
double code(double w0, double M, double D, double h, double l, double d) {
	return 2.0 * d;
}
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 = 2.0d0 * d_1
end function
public static double code(double w0, double M, double D, double h, double l, double d) {
	return 2.0 * d;
}
def code(w0, M, D, h, l, d):
	return 2.0 * d
function code(w0, M, D, h, l, d)
	return Float64(2.0 * d)
end
function tmp = code(w0, M, D, h, l, d)
	tmp = 2.0 * d;
end
code[w0_, M_, D_, h_, l_, d_] := N[(2.0 * d), $MachinePrecision]
\begin{array}{l}

\\
2 \cdot d
\end{array}
Derivation
  1. Initial program 78.7%

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

    \[\leadsto \color{blue}{w0 + {M}^{2} \cdot \left(\frac{-1}{8} \cdot \frac{{D}^{2} \cdot \left(h \cdot w0\right)}{{d}^{2} \cdot \ell} + \frac{-1}{128} \cdot \frac{{D}^{4} \cdot \left({M}^{2} \cdot \left({h}^{2} \cdot w0\right)\right)}{{d}^{4} \cdot {\ell}^{2}}\right)} \]
  4. Applied rewrites9.9%

    \[\leadsto \color{blue}{{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]
  5. Taylor expanded in M around 0

    \[\leadsto \frac{1}{4} \cdot \color{blue}{\frac{{D}^{2} \cdot \left({M}^{2} \cdot h\right)}{{d}^{2} \cdot \ell}} \]
  6. Applied rewrites3.0%

    \[\leadsto 2 \cdot \color{blue}{d} \]
  7. Add Preprocessing

Reproduce

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