Henrywood and Agarwal, Equation (9a)

Percentage Accurate: 81.7% → 86.9%
Time: 17.8s
Alternatives: 16
Speedup: 1.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 16 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.7% 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: 86.9% accurate, 0.7× speedup?

\[\begin{array}{l} D_m = \left|D\right| \\ [w0, M, D_m, h, l, d] = \mathsf{sort}([w0, M, D_m, h, l, d])\\ \\ \begin{array}{l} \mathbf{if}\;\frac{h}{\ell} \cdot {\left(\frac{D\_m \cdot M}{2 \cdot d}\right)}^{2} \leq 4 \cdot 10^{-44}:\\ \;\;\;\;\sqrt{\mathsf{fma}\left(\left(\left(\frac{D\_m}{d} \cdot M\right) \cdot -0.5\right) \cdot \frac{h}{\ell}, D\_m \cdot \left(M \cdot \frac{0.5}{d}\right), 1\right)} \cdot w0\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\mathsf{fma}\left(\left(\frac{-0.25 \cdot M}{\ell} \cdot M\right) \cdot \frac{D\_m}{d}, \frac{D\_m}{d} \cdot h, 1\right)} \cdot w0\\ \end{array} \end{array} \]
D_m = (fabs.f64 D)
NOTE: w0, M, D_m, h, l, and d should be sorted in increasing order before calling this function.
(FPCore (w0 M D_m h l d)
 :precision binary64
 (if (<= (* (/ h l) (pow (/ (* D_m M) (* 2.0 d)) 2.0)) 4e-44)
   (*
    (sqrt
     (fma (* (* (* (/ D_m d) M) -0.5) (/ h l)) (* D_m (* M (/ 0.5 d))) 1.0))
    w0)
   (*
    (sqrt (fma (* (* (/ (* -0.25 M) l) M) (/ D_m d)) (* (/ D_m d) h) 1.0))
    w0)))
D_m = fabs(D);
assert(w0 < M && M < D_m && D_m < h && h < l && l < d);
double code(double w0, double M, double D_m, double h, double l, double d) {
	double tmp;
	if (((h / l) * pow(((D_m * M) / (2.0 * d)), 2.0)) <= 4e-44) {
		tmp = sqrt(fma(((((D_m / d) * M) * -0.5) * (h / l)), (D_m * (M * (0.5 / d))), 1.0)) * w0;
	} else {
		tmp = sqrt(fma(((((-0.25 * M) / l) * M) * (D_m / d)), ((D_m / d) * h), 1.0)) * w0;
	}
	return tmp;
}
D_m = abs(D)
w0, M, D_m, h, l, d = sort([w0, M, D_m, h, l, d])
function code(w0, M, D_m, h, l, d)
	tmp = 0.0
	if (Float64(Float64(h / l) * (Float64(Float64(D_m * M) / Float64(2.0 * d)) ^ 2.0)) <= 4e-44)
		tmp = Float64(sqrt(fma(Float64(Float64(Float64(Float64(D_m / d) * M) * -0.5) * Float64(h / l)), Float64(D_m * Float64(M * Float64(0.5 / d))), 1.0)) * w0);
	else
		tmp = Float64(sqrt(fma(Float64(Float64(Float64(Float64(-0.25 * M) / l) * M) * Float64(D_m / d)), Float64(Float64(D_m / d) * h), 1.0)) * w0);
	end
	return tmp
end
D_m = N[Abs[D], $MachinePrecision]
NOTE: w0, M, D_m, h, l, and d should be sorted in increasing order before calling this function.
code[w0_, M_, D$95$m_, h_, l_, d_] := If[LessEqual[N[(N[(h / l), $MachinePrecision] * N[Power[N[(N[(D$95$m * M), $MachinePrecision] / N[(2.0 * d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision], 4e-44], N[(N[Sqrt[N[(N[(N[(N[(N[(D$95$m / d), $MachinePrecision] * M), $MachinePrecision] * -0.5), $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision] * N[(D$95$m * N[(M * N[(0.5 / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision] * w0), $MachinePrecision], N[(N[Sqrt[N[(N[(N[(N[(N[(-0.25 * M), $MachinePrecision] / l), $MachinePrecision] * M), $MachinePrecision] * N[(D$95$m / d), $MachinePrecision]), $MachinePrecision] * N[(N[(D$95$m / d), $MachinePrecision] * h), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision] * w0), $MachinePrecision]]
\begin{array}{l}
D_m = \left|D\right|
\\
[w0, M, D_m, h, l, d] = \mathsf{sort}([w0, M, D_m, h, l, d])\\
\\
\begin{array}{l}
\mathbf{if}\;\frac{h}{\ell} \cdot {\left(\frac{D\_m \cdot M}{2 \cdot d}\right)}^{2} \leq 4 \cdot 10^{-44}:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(\left(\left(\frac{D\_m}{d} \cdot M\right) \cdot -0.5\right) \cdot \frac{h}{\ell}, D\_m \cdot \left(M \cdot \frac{0.5}{d}\right), 1\right)} \cdot w0\\

\mathbf{else}:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(\left(\frac{-0.25 \cdot M}{\ell} \cdot M\right) \cdot \frac{D\_m}{d}, \frac{D\_m}{d} \cdot h, 1\right)} \cdot 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)) < 3.99999999999999981e-44

    1. Initial program 89.9%

      \[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift--.f64N/A

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

        \[\leadsto w0 \cdot \sqrt{\color{blue}{1 + \left(\mathsf{neg}\left({\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)}} \]
      3. +-commutativeN/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{\left(\mathsf{neg}\left({\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right) + 1}} \]
      4. lift-*.f64N/A

        \[\leadsto w0 \cdot \sqrt{\left(\mathsf{neg}\left(\color{blue}{{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}}\right)\right) + 1} \]
      5. *-commutativeN/A

        \[\leadsto w0 \cdot \sqrt{\left(\mathsf{neg}\left(\color{blue}{\frac{h}{\ell} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}}\right)\right) + 1} \]
      6. distribute-rgt-neg-inN/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{\frac{h}{\ell} \cdot \left(\mathsf{neg}\left({\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right)\right)} + 1} \]
      7. lift-pow.f64N/A

        \[\leadsto w0 \cdot \sqrt{\frac{h}{\ell} \cdot \left(\mathsf{neg}\left(\color{blue}{{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}}\right)\right) + 1} \]
      8. unpow2N/A

        \[\leadsto w0 \cdot \sqrt{\frac{h}{\ell} \cdot \left(\mathsf{neg}\left(\color{blue}{\frac{M \cdot D}{2 \cdot d} \cdot \frac{M \cdot D}{2 \cdot d}}\right)\right) + 1} \]
      9. distribute-lft-neg-inN/A

        \[\leadsto w0 \cdot \sqrt{\frac{h}{\ell} \cdot \color{blue}{\left(\left(\mathsf{neg}\left(\frac{M \cdot D}{2 \cdot d}\right)\right) \cdot \frac{M \cdot D}{2 \cdot d}\right)} + 1} \]
      10. associate-*r*N/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{\left(\frac{h}{\ell} \cdot \left(\mathsf{neg}\left(\frac{M \cdot D}{2 \cdot d}\right)\right)\right) \cdot \frac{M \cdot D}{2 \cdot d}} + 1} \]
      11. lower-fma.f64N/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{\mathsf{fma}\left(\frac{h}{\ell} \cdot \left(\mathsf{neg}\left(\frac{M \cdot D}{2 \cdot d}\right)\right), \frac{M \cdot D}{2 \cdot d}, 1\right)}} \]
    4. Applied rewrites90.5%

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

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

    1. Initial program 4.0%

      \[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift--.f64N/A

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

        \[\leadsto w0 \cdot \sqrt{\color{blue}{1 + \left(\mathsf{neg}\left({\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)}} \]
      3. +-commutativeN/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{\left(\mathsf{neg}\left({\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right) + 1}} \]
      4. lift-*.f64N/A

        \[\leadsto w0 \cdot \sqrt{\left(\mathsf{neg}\left(\color{blue}{{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}}\right)\right) + 1} \]
      5. lift-/.f64N/A

        \[\leadsto w0 \cdot \sqrt{\left(\mathsf{neg}\left({\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \color{blue}{\frac{h}{\ell}}\right)\right) + 1} \]
      6. associate-*r/N/A

        \[\leadsto w0 \cdot \sqrt{\left(\mathsf{neg}\left(\color{blue}{\frac{{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot h}{\ell}}\right)\right) + 1} \]
      7. distribute-neg-frac2N/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{\frac{{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot h}{\mathsf{neg}\left(\ell\right)}} + 1} \]
      8. lift-pow.f64N/A

        \[\leadsto w0 \cdot \sqrt{\frac{\color{blue}{{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}} \cdot h}{\mathsf{neg}\left(\ell\right)} + 1} \]
      9. unpow2N/A

        \[\leadsto w0 \cdot \sqrt{\frac{\color{blue}{\left(\frac{M \cdot D}{2 \cdot d} \cdot \frac{M \cdot D}{2 \cdot d}\right)} \cdot h}{\mathsf{neg}\left(\ell\right)} + 1} \]
      10. associate-*l*N/A

        \[\leadsto w0 \cdot \sqrt{\frac{\color{blue}{\frac{M \cdot D}{2 \cdot d} \cdot \left(\frac{M \cdot D}{2 \cdot d} \cdot h\right)}}{\mathsf{neg}\left(\ell\right)} + 1} \]
      11. associate-/l*N/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{\frac{M \cdot D}{2 \cdot d} \cdot \frac{\frac{M \cdot D}{2 \cdot d} \cdot h}{\mathsf{neg}\left(\ell\right)}} + 1} \]
      12. lower-fma.f64N/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{\mathsf{fma}\left(\frac{M \cdot D}{2 \cdot d}, \frac{\frac{M \cdot D}{2 \cdot d} \cdot h}{\mathsf{neg}\left(\ell\right)}, 1\right)}} \]
    4. Applied rewrites84.7%

      \[\leadsto w0 \cdot \sqrt{\color{blue}{\mathsf{fma}\left(\left(\frac{0.5}{d} \cdot M\right) \cdot D, \frac{\left(D \cdot 0.5\right) \cdot \left(\frac{M}{d} \cdot h\right)}{-\ell}, 1\right)}} \]
    5. Applied rewrites84.8%

      \[\leadsto w0 \cdot \sqrt{\color{blue}{\mathsf{fma}\left(\frac{\left(M \cdot M\right) \cdot -0.25}{\ell} \cdot \frac{D}{d}, \frac{D}{d} \cdot h, 1\right)}} \]
    6. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto w0 \cdot \sqrt{\mathsf{fma}\left(\color{blue}{\frac{\left(M \cdot M\right) \cdot \frac{-1}{4}}{\ell}} \cdot \frac{D}{d}, \frac{D}{d} \cdot h, 1\right)} \]
      2. lift-*.f64N/A

        \[\leadsto w0 \cdot \sqrt{\mathsf{fma}\left(\frac{\color{blue}{\left(M \cdot M\right) \cdot \frac{-1}{4}}}{\ell} \cdot \frac{D}{d}, \frac{D}{d} \cdot h, 1\right)} \]
      3. lift-*.f64N/A

        \[\leadsto w0 \cdot \sqrt{\mathsf{fma}\left(\frac{\color{blue}{\left(M \cdot M\right)} \cdot \frac{-1}{4}}{\ell} \cdot \frac{D}{d}, \frac{D}{d} \cdot h, 1\right)} \]
      4. associate-*l*N/A

        \[\leadsto w0 \cdot \sqrt{\mathsf{fma}\left(\frac{\color{blue}{M \cdot \left(M \cdot \frac{-1}{4}\right)}}{\ell} \cdot \frac{D}{d}, \frac{D}{d} \cdot h, 1\right)} \]
      5. associate-/l*N/A

        \[\leadsto w0 \cdot \sqrt{\mathsf{fma}\left(\color{blue}{\left(M \cdot \frac{M \cdot \frac{-1}{4}}{\ell}\right)} \cdot \frac{D}{d}, \frac{D}{d} \cdot h, 1\right)} \]
      6. lower-*.f64N/A

        \[\leadsto w0 \cdot \sqrt{\mathsf{fma}\left(\color{blue}{\left(M \cdot \frac{M \cdot \frac{-1}{4}}{\ell}\right)} \cdot \frac{D}{d}, \frac{D}{d} \cdot h, 1\right)} \]
      7. lower-/.f64N/A

        \[\leadsto w0 \cdot \sqrt{\mathsf{fma}\left(\left(M \cdot \color{blue}{\frac{M \cdot \frac{-1}{4}}{\ell}}\right) \cdot \frac{D}{d}, \frac{D}{d} \cdot h, 1\right)} \]
      8. *-commutativeN/A

        \[\leadsto w0 \cdot \sqrt{\mathsf{fma}\left(\left(M \cdot \frac{\color{blue}{\frac{-1}{4} \cdot M}}{\ell}\right) \cdot \frac{D}{d}, \frac{D}{d} \cdot h, 1\right)} \]
      9. lower-*.f6496.1

        \[\leadsto w0 \cdot \sqrt{\mathsf{fma}\left(\left(M \cdot \frac{\color{blue}{-0.25 \cdot M}}{\ell}\right) \cdot \frac{D}{d}, \frac{D}{d} \cdot h, 1\right)} \]
    7. Applied rewrites96.1%

      \[\leadsto w0 \cdot \sqrt{\mathsf{fma}\left(\color{blue}{\left(M \cdot \frac{-0.25 \cdot M}{\ell}\right)} \cdot \frac{D}{d}, \frac{D}{d} \cdot h, 1\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification91.0%

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

Alternative 2: 83.6% accurate, 0.7× speedup?

\[\begin{array}{l} D_m = \left|D\right| \\ [w0, M, D_m, h, l, d] = \mathsf{sort}([w0, M, D_m, h, l, d])\\ \\ \begin{array}{l} \mathbf{if}\;1 - \frac{h}{\ell} \cdot {\left(\frac{D\_m \cdot M}{2 \cdot d}\right)}^{2} \leq 1:\\ \;\;\;\;1 \cdot w0\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\mathsf{fma}\left(-D\_m, \frac{\left(\left(D\_m \cdot M\right) \cdot h\right) \cdot M}{\left(\left(4 \cdot \ell\right) \cdot d\right) \cdot d}, 1\right)} \cdot w0\\ \end{array} \end{array} \]
D_m = (fabs.f64 D)
NOTE: w0, M, D_m, h, l, and d should be sorted in increasing order before calling this function.
(FPCore (w0 M D_m h l d)
 :precision binary64
 (if (<= (- 1.0 (* (/ h l) (pow (/ (* D_m M) (* 2.0 d)) 2.0))) 1.0)
   (* 1.0 w0)
   (*
    (sqrt (fma (- D_m) (/ (* (* (* D_m M) h) M) (* (* (* 4.0 l) d) d)) 1.0))
    w0)))
D_m = fabs(D);
assert(w0 < M && M < D_m && D_m < h && h < l && l < d);
double code(double w0, double M, double D_m, double h, double l, double d) {
	double tmp;
	if ((1.0 - ((h / l) * pow(((D_m * M) / (2.0 * d)), 2.0))) <= 1.0) {
		tmp = 1.0 * w0;
	} else {
		tmp = sqrt(fma(-D_m, ((((D_m * M) * h) * M) / (((4.0 * l) * d) * d)), 1.0)) * w0;
	}
	return tmp;
}
D_m = abs(D)
w0, M, D_m, h, l, d = sort([w0, M, D_m, h, l, d])
function code(w0, M, D_m, h, l, d)
	tmp = 0.0
	if (Float64(1.0 - Float64(Float64(h / l) * (Float64(Float64(D_m * M) / Float64(2.0 * d)) ^ 2.0))) <= 1.0)
		tmp = Float64(1.0 * w0);
	else
		tmp = Float64(sqrt(fma(Float64(-D_m), Float64(Float64(Float64(Float64(D_m * M) * h) * M) / Float64(Float64(Float64(4.0 * l) * d) * d)), 1.0)) * w0);
	end
	return tmp
end
D_m = N[Abs[D], $MachinePrecision]
NOTE: w0, M, D_m, h, l, and d should be sorted in increasing order before calling this function.
code[w0_, M_, D$95$m_, h_, l_, d_] := If[LessEqual[N[(1.0 - N[(N[(h / l), $MachinePrecision] * N[Power[N[(N[(D$95$m * M), $MachinePrecision] / N[(2.0 * d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1.0], N[(1.0 * w0), $MachinePrecision], N[(N[Sqrt[N[((-D$95$m) * N[(N[(N[(N[(D$95$m * M), $MachinePrecision] * h), $MachinePrecision] * M), $MachinePrecision] / N[(N[(N[(4.0 * l), $MachinePrecision] * d), $MachinePrecision] * d), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision] * w0), $MachinePrecision]]
\begin{array}{l}
D_m = \left|D\right|
\\
[w0, M, D_m, h, l, d] = \mathsf{sort}([w0, M, D_m, h, l, d])\\
\\
\begin{array}{l}
\mathbf{if}\;1 - \frac{h}{\ell} \cdot {\left(\frac{D\_m \cdot M}{2 \cdot d}\right)}^{2} \leq 1:\\
\;\;\;\;1 \cdot w0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.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

    1. Initial program 99.6%

      \[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 w0 \cdot \color{blue}{1} \]
    4. Step-by-step derivation
      1. Applied rewrites99.4%

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

      if 1 < (-.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 53.3%

        \[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]
      2. Add Preprocessing
      3. Step-by-step derivation
        1. lift-*.f64N/A

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

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

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

          \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\frac{{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}}{\frac{\ell}{h}}}} \]
        5. lift-pow.f64N/A

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

          \[\leadsto w0 \cdot \sqrt{1 - \frac{\color{blue}{\frac{M \cdot D}{2 \cdot d} \cdot \frac{M \cdot D}{2 \cdot d}}}{\frac{\ell}{h}}} \]
        7. lift-/.f64N/A

          \[\leadsto w0 \cdot \sqrt{1 - \frac{\frac{M \cdot D}{2 \cdot d} \cdot \color{blue}{\frac{M \cdot D}{2 \cdot d}}}{\frac{\ell}{h}}} \]
        8. clear-numN/A

          \[\leadsto w0 \cdot \sqrt{1 - \frac{\frac{M \cdot D}{2 \cdot d} \cdot \color{blue}{\frac{1}{\frac{2 \cdot d}{M \cdot D}}}}{\frac{\ell}{h}}} \]
        9. un-div-invN/A

          \[\leadsto w0 \cdot \sqrt{1 - \frac{\color{blue}{\frac{\frac{M \cdot D}{2 \cdot d}}{\frac{2 \cdot d}{M \cdot D}}}}{\frac{\ell}{h}}} \]
        10. lift-/.f64N/A

          \[\leadsto w0 \cdot \sqrt{1 - \frac{\frac{\color{blue}{\frac{M \cdot D}{2 \cdot d}}}{\frac{2 \cdot d}{M \cdot D}}}{\frac{\ell}{h}}} \]
        11. associate-/r*N/A

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

          \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\frac{M \cdot D}{\frac{\ell}{h} \cdot \left(\left(2 \cdot d\right) \cdot \frac{2 \cdot d}{M \cdot D}\right)}}} \]
        13. lower-/.f64N/A

          \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\frac{M \cdot D}{\frac{\ell}{h} \cdot \left(\left(2 \cdot d\right) \cdot \frac{2 \cdot d}{M \cdot D}\right)}}} \]
        14. lift-*.f64N/A

          \[\leadsto w0 \cdot \sqrt{1 - \frac{\color{blue}{M \cdot D}}{\frac{\ell}{h} \cdot \left(\left(2 \cdot d\right) \cdot \frac{2 \cdot d}{M \cdot D}\right)}} \]
        15. *-commutativeN/A

          \[\leadsto w0 \cdot \sqrt{1 - \frac{\color{blue}{D \cdot M}}{\frac{\ell}{h} \cdot \left(\left(2 \cdot d\right) \cdot \frac{2 \cdot d}{M \cdot D}\right)}} \]
        16. lower-*.f64N/A

          \[\leadsto w0 \cdot \sqrt{1 - \frac{\color{blue}{D \cdot M}}{\frac{\ell}{h} \cdot \left(\left(2 \cdot d\right) \cdot \frac{2 \cdot d}{M \cdot D}\right)}} \]
        17. lower-*.f64N/A

          \[\leadsto w0 \cdot \sqrt{1 - \frac{D \cdot M}{\color{blue}{\frac{\ell}{h} \cdot \left(\left(2 \cdot d\right) \cdot \frac{2 \cdot d}{M \cdot D}\right)}}} \]
        18. lower-/.f64N/A

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

          \[\leadsto w0 \cdot \sqrt{1 - \frac{D \cdot M}{\frac{\ell}{h} \cdot \color{blue}{\frac{\left(2 \cdot d\right) \cdot \left(2 \cdot d\right)}{M \cdot D}}}} \]
        20. lower-/.f64N/A

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

        \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\frac{D \cdot M}{\frac{\ell}{h} \cdot \frac{4 \cdot \left(d \cdot d\right)}{D \cdot M}}}} \]
      5. Step-by-step derivation
        1. lift-*.f64N/A

          \[\leadsto \color{blue}{w0 \cdot \sqrt{1 - \frac{D \cdot M}{\frac{\ell}{h} \cdot \frac{4 \cdot \left(d \cdot d\right)}{D \cdot M}}}} \]
        2. *-commutativeN/A

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

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

        \[\leadsto \color{blue}{\sqrt{\mathsf{fma}\left(-D, \frac{M}{\left(4 \cdot \left(d \cdot d\right)\right) \cdot \ell} \cdot \left(\left(h \cdot M\right) \cdot D\right), 1\right)} \cdot w0} \]
      7. Step-by-step derivation
        1. lift-*.f64N/A

          \[\leadsto \sqrt{\mathsf{fma}\left(\mathsf{neg}\left(D\right), \color{blue}{\frac{M}{\left(4 \cdot \left(d \cdot d\right)\right) \cdot \ell} \cdot \left(\left(h \cdot M\right) \cdot D\right)}, 1\right)} \cdot w0 \]
        2. lift-/.f64N/A

          \[\leadsto \sqrt{\mathsf{fma}\left(\mathsf{neg}\left(D\right), \color{blue}{\frac{M}{\left(4 \cdot \left(d \cdot d\right)\right) \cdot \ell}} \cdot \left(\left(h \cdot M\right) \cdot D\right), 1\right)} \cdot w0 \]
        3. associate-*l/N/A

          \[\leadsto \sqrt{\mathsf{fma}\left(\mathsf{neg}\left(D\right), \color{blue}{\frac{M \cdot \left(\left(h \cdot M\right) \cdot D\right)}{\left(4 \cdot \left(d \cdot d\right)\right) \cdot \ell}}, 1\right)} \cdot w0 \]
        4. lower-/.f64N/A

          \[\leadsto \sqrt{\mathsf{fma}\left(\mathsf{neg}\left(D\right), \color{blue}{\frac{M \cdot \left(\left(h \cdot M\right) \cdot D\right)}{\left(4 \cdot \left(d \cdot d\right)\right) \cdot \ell}}, 1\right)} \cdot w0 \]
        5. *-commutativeN/A

          \[\leadsto \sqrt{\mathsf{fma}\left(\mathsf{neg}\left(D\right), \frac{\color{blue}{\left(\left(h \cdot M\right) \cdot D\right) \cdot M}}{\left(4 \cdot \left(d \cdot d\right)\right) \cdot \ell}, 1\right)} \cdot w0 \]
        6. lower-*.f6454.0

          \[\leadsto \sqrt{\mathsf{fma}\left(-D, \frac{\color{blue}{\left(\left(h \cdot M\right) \cdot D\right) \cdot M}}{\left(4 \cdot \left(d \cdot d\right)\right) \cdot \ell}, 1\right)} \cdot w0 \]
        7. lift-*.f64N/A

          \[\leadsto \sqrt{\mathsf{fma}\left(\mathsf{neg}\left(D\right), \frac{\color{blue}{\left(\left(h \cdot M\right) \cdot D\right)} \cdot M}{\left(4 \cdot \left(d \cdot d\right)\right) \cdot \ell}, 1\right)} \cdot w0 \]
        8. lift-*.f64N/A

          \[\leadsto \sqrt{\mathsf{fma}\left(\mathsf{neg}\left(D\right), \frac{\left(\color{blue}{\left(h \cdot M\right)} \cdot D\right) \cdot M}{\left(4 \cdot \left(d \cdot d\right)\right) \cdot \ell}, 1\right)} \cdot w0 \]
        9. associate-*l*N/A

          \[\leadsto \sqrt{\mathsf{fma}\left(\mathsf{neg}\left(D\right), \frac{\color{blue}{\left(h \cdot \left(M \cdot D\right)\right)} \cdot M}{\left(4 \cdot \left(d \cdot d\right)\right) \cdot \ell}, 1\right)} \cdot w0 \]
        10. lift-*.f64N/A

          \[\leadsto \sqrt{\mathsf{fma}\left(\mathsf{neg}\left(D\right), \frac{\left(h \cdot \color{blue}{\left(M \cdot D\right)}\right) \cdot M}{\left(4 \cdot \left(d \cdot d\right)\right) \cdot \ell}, 1\right)} \cdot w0 \]
        11. lower-*.f6454.3

          \[\leadsto \sqrt{\mathsf{fma}\left(-D, \frac{\color{blue}{\left(h \cdot \left(M \cdot D\right)\right)} \cdot M}{\left(4 \cdot \left(d \cdot d\right)\right) \cdot \ell}, 1\right)} \cdot w0 \]
        12. lift-*.f64N/A

          \[\leadsto \sqrt{\mathsf{fma}\left(\mathsf{neg}\left(D\right), \frac{\left(h \cdot \color{blue}{\left(M \cdot D\right)}\right) \cdot M}{\left(4 \cdot \left(d \cdot d\right)\right) \cdot \ell}, 1\right)} \cdot w0 \]
        13. *-commutativeN/A

          \[\leadsto \sqrt{\mathsf{fma}\left(\mathsf{neg}\left(D\right), \frac{\left(h \cdot \color{blue}{\left(D \cdot M\right)}\right) \cdot M}{\left(4 \cdot \left(d \cdot d\right)\right) \cdot \ell}, 1\right)} \cdot w0 \]
        14. lower-*.f6454.3

          \[\leadsto \sqrt{\mathsf{fma}\left(-D, \frac{\left(h \cdot \color{blue}{\left(D \cdot M\right)}\right) \cdot M}{\left(4 \cdot \left(d \cdot d\right)\right) \cdot \ell}, 1\right)} \cdot w0 \]
        15. lift-*.f64N/A

          \[\leadsto \sqrt{\mathsf{fma}\left(\mathsf{neg}\left(D\right), \frac{\left(h \cdot \left(D \cdot M\right)\right) \cdot M}{\color{blue}{\left(4 \cdot \left(d \cdot d\right)\right) \cdot \ell}}, 1\right)} \cdot w0 \]
        16. *-commutativeN/A

          \[\leadsto \sqrt{\mathsf{fma}\left(\mathsf{neg}\left(D\right), \frac{\left(h \cdot \left(D \cdot M\right)\right) \cdot M}{\color{blue}{\ell \cdot \left(4 \cdot \left(d \cdot d\right)\right)}}, 1\right)} \cdot w0 \]
        17. lift-*.f64N/A

          \[\leadsto \sqrt{\mathsf{fma}\left(\mathsf{neg}\left(D\right), \frac{\left(h \cdot \left(D \cdot M\right)\right) \cdot M}{\ell \cdot \color{blue}{\left(4 \cdot \left(d \cdot d\right)\right)}}, 1\right)} \cdot w0 \]
        18. lift-*.f64N/A

          \[\leadsto \sqrt{\mathsf{fma}\left(\mathsf{neg}\left(D\right), \frac{\left(h \cdot \left(D \cdot M\right)\right) \cdot M}{\ell \cdot \left(4 \cdot \color{blue}{\left(d \cdot d\right)}\right)}, 1\right)} \cdot w0 \]
        19. associate-*r*N/A

          \[\leadsto \sqrt{\mathsf{fma}\left(\mathsf{neg}\left(D\right), \frac{\left(h \cdot \left(D \cdot M\right)\right) \cdot M}{\ell \cdot \color{blue}{\left(\left(4 \cdot d\right) \cdot d\right)}}, 1\right)} \cdot w0 \]
        20. associate-*r*N/A

          \[\leadsto \sqrt{\mathsf{fma}\left(\mathsf{neg}\left(D\right), \frac{\left(h \cdot \left(D \cdot M\right)\right) \cdot M}{\color{blue}{\left(\ell \cdot \left(4 \cdot d\right)\right) \cdot d}}, 1\right)} \cdot w0 \]
        21. associate-*l*N/A

          \[\leadsto \sqrt{\mathsf{fma}\left(\mathsf{neg}\left(D\right), \frac{\left(h \cdot \left(D \cdot M\right)\right) \cdot M}{\color{blue}{\left(\left(\ell \cdot 4\right) \cdot d\right)} \cdot d}, 1\right)} \cdot w0 \]
        22. lift-*.f64N/A

          \[\leadsto \sqrt{\mathsf{fma}\left(\mathsf{neg}\left(D\right), \frac{\left(h \cdot \left(D \cdot M\right)\right) \cdot M}{\left(\color{blue}{\left(\ell \cdot 4\right)} \cdot d\right) \cdot d}, 1\right)} \cdot w0 \]
        23. lower-*.f64N/A

          \[\leadsto \sqrt{\mathsf{fma}\left(\mathsf{neg}\left(D\right), \frac{\left(h \cdot \left(D \cdot M\right)\right) \cdot M}{\color{blue}{\left(\left(\ell \cdot 4\right) \cdot d\right) \cdot d}}, 1\right)} \cdot w0 \]
      8. Applied rewrites58.3%

        \[\leadsto \sqrt{\mathsf{fma}\left(-D, \color{blue}{\frac{\left(h \cdot \left(D \cdot M\right)\right) \cdot M}{\left(d \cdot \left(4 \cdot \ell\right)\right) \cdot d}}, 1\right)} \cdot w0 \]
    5. Recombined 2 regimes into one program.
    6. Final simplification83.6%

      \[\leadsto \begin{array}{l} \mathbf{if}\;1 - \frac{h}{\ell} \cdot {\left(\frac{D \cdot M}{2 \cdot d}\right)}^{2} \leq 1:\\ \;\;\;\;1 \cdot w0\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\mathsf{fma}\left(-D, \frac{\left(\left(D \cdot M\right) \cdot h\right) \cdot M}{\left(\left(4 \cdot \ell\right) \cdot d\right) \cdot d}, 1\right)} \cdot w0\\ \end{array} \]
    7. Add Preprocessing

    Reproduce

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