Henrywood and Agarwal, Equation (9a)

Percentage Accurate: 81.5% → 88.7%
Time: 19.2s
Alternatives: 23
Speedup: 1.8×

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 23 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.5% 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: 88.7% accurate, 1.4× speedup?

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

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


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

    1. Initial program 87.7%

      \[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. lift-pow.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 4e-30 < (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d))

    1. Initial program 70.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 rewrites74.0%

      \[\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)}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification89.9%

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

Alternative 2: 88.4% accurate, 0.7× speedup?

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

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


\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))) < 9.9999999999999992e292

    1. Initial program 99.7%

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

      \[\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 9.9999999999999992e292 < (-.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 43.4%

      \[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. lift-pow.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;1 - \frac{h}{\ell} \cdot {\left(\frac{M \cdot D}{d \cdot 2}\right)}^{2} \leq 10^{+293}:\\ \;\;\;\;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(\frac{M \cdot D}{\left(d \cdot -2\right) \cdot \ell}, \left(M \cdot D\right) \cdot \left(h \cdot \frac{0.5}{d}\right), 1\right)}\\ \end{array} \]
    8. Add Preprocessing

    Reproduce

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