Henrywood and Agarwal, Equation (9a)

Percentage Accurate: 81.6% → 87.9%
Time: 20.0s
Alternatives: 19
Speedup: 2.1×

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 19 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.6% 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: 87.9% accurate, 0.7× speedup?

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

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


\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)) < 1.99999999999999988e-11

    1. Initial program 87.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. distribute-lft-neg-inN/A

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

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

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

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

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

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

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

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

    1. Initial program 7.1%

      \[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 \sqrt{\color{blue}{1 + \frac{-1}{4} \cdot \frac{{D}^{2} \cdot \left({M}^{2} \cdot h\right)}{{d}^{2} \cdot \ell}}} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

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

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

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

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

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

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

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

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

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

        \[\leadsto w0 \cdot \sqrt{\mathsf{fma}\left(D \cdot \frac{h \cdot \left(-0.25 \cdot \left(M \cdot M\right)\right)}{d \cdot \left(d \cdot \ell\right)}, \color{blue}{D}, 1\right)} \]
      2. Step-by-step derivation
        1. Applied rewrites93.3%

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

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

      Alternative 2: 83.6% accurate, 0.7× speedup?

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

        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. 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. distribute-lft-neg-inN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        1. Initial program 89.4%

          \[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 rewrites96.4%

            \[\leadsto w0 \cdot \color{blue}{1} \]
        5. Recombined 2 regimes into one program.
        6. Final simplification83.6%

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

        Reproduce

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