Henrywood and Agarwal, Equation (9a)

Percentage Accurate: 81.4% → 89.6%
Time: 16.7s
Alternatives: 5
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 5 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.4% 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: 89.6% accurate, 1.8× 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])\\ \\ w0 \cdot \sqrt{1 - \frac{h \cdot \left(D\_m \cdot \frac{M}{\frac{d}{0.5}}\right)}{\ell} \cdot \left(D\_m \cdot \frac{M \cdot 0.5}{d}\right)} \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
 (*
  w0
  (sqrt
   (- 1.0 (* (/ (* h (* D_m (/ M (/ d 0.5)))) l) (* D_m (/ (* M 0.5) d)))))))
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) {
	return w0 * sqrt((1.0 - (((h * (D_m * (M / (d / 0.5)))) / l) * (D_m * ((M * 0.5) / d)))));
}
D_m = abs(D)
NOTE: w0, M, D_m, h, l, and d should be sorted in increasing order before calling this function.
real(8) function code(w0, m, d_m, h, l, d)
    real(8), intent (in) :: w0
    real(8), intent (in) :: m
    real(8), intent (in) :: d_m
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: d
    code = w0 * sqrt((1.0d0 - (((h * (d_m * (m / (d / 0.5d0)))) / l) * (d_m * ((m * 0.5d0) / d)))))
end function
D_m = Math.abs(D);
assert w0 < M && M < D_m && D_m < h && h < l && l < d;
public static double code(double w0, double M, double D_m, double h, double l, double d) {
	return w0 * Math.sqrt((1.0 - (((h * (D_m * (M / (d / 0.5)))) / l) * (D_m * ((M * 0.5) / d)))));
}
D_m = math.fabs(D)
[w0, M, D_m, h, l, d] = sort([w0, M, D_m, h, l, d])
def code(w0, M, D_m, h, l, d):
	return w0 * math.sqrt((1.0 - (((h * (D_m * (M / (d / 0.5)))) / l) * (D_m * ((M * 0.5) / d)))))
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)
	return Float64(w0 * sqrt(Float64(1.0 - Float64(Float64(Float64(h * Float64(D_m * Float64(M / Float64(d / 0.5)))) / l) * Float64(D_m * Float64(Float64(M * 0.5) / d))))))
end
D_m = abs(D);
w0, M, D_m, h, l, d = num2cell(sort([w0, M, D_m, h, l, d])){:}
function tmp = code(w0, M, D_m, h, l, d)
	tmp = w0 * sqrt((1.0 - (((h * (D_m * (M / (d / 0.5)))) / l) * (D_m * ((M * 0.5) / d)))));
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_] := N[(w0 * N[Sqrt[N[(1.0 - N[(N[(N[(h * N[(D$95$m * N[(M / N[(d / 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision] * N[(D$95$m * N[(N[(M * 0.5), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $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])\\
\\
w0 \cdot \sqrt{1 - \frac{h \cdot \left(D\_m \cdot \frac{M}{\frac{d}{0.5}}\right)}{\ell} \cdot \left(D\_m \cdot \frac{M \cdot 0.5}{d}\right)}
\end{array}
Derivation
  1. Initial program 79.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\left(\frac{h}{\ell} \cdot \left(D \cdot \frac{M \cdot 0.5}{d}\right)\right) \cdot \left(D \cdot \frac{M \cdot 0.5}{d}\right)}} \]
  8. Step-by-step derivation
    1. associate-*l/87.3%

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

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

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

Alternative 2: 87.7% accurate, 1.6× 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} t_0 := \frac{D\_m \cdot \left(M \cdot 0.5\right)}{d}\\ t_1 := w0 \cdot \sqrt{1 - \frac{0.5 \cdot \frac{D\_m \cdot \left(M \cdot h\right)}{d}}{\ell} \cdot \left(D\_m \cdot \frac{M \cdot 0.5}{d}\right)}\\ \mathbf{if}\;\frac{h}{\ell} \leq -1 \cdot 10^{+264}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\frac{h}{\ell} \leq -1 \cdot 10^{-95}:\\ \;\;\;\;w0 \cdot \sqrt{1 - \left(\frac{h}{\ell} \cdot t\_0\right) \cdot t\_0}\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \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
 (let* ((t_0 (/ (* D_m (* M 0.5)) d))
        (t_1
         (*
          w0
          (sqrt
           (-
            1.0
            (*
             (/ (* 0.5 (/ (* D_m (* M h)) d)) l)
             (* D_m (/ (* M 0.5) d))))))))
   (if (<= (/ h l) -1e+264)
     t_1
     (if (<= (/ h l) -1e-95)
       (* w0 (sqrt (- 1.0 (* (* (/ h l) t_0) t_0))))
       t_1))))
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 t_0 = (D_m * (M * 0.5)) / d;
	double t_1 = w0 * sqrt((1.0 - (((0.5 * ((D_m * (M * h)) / d)) / l) * (D_m * ((M * 0.5) / d)))));
	double tmp;
	if ((h / l) <= -1e+264) {
		tmp = t_1;
	} else if ((h / l) <= -1e-95) {
		tmp = w0 * sqrt((1.0 - (((h / l) * t_0) * t_0)));
	} else {
		tmp = t_1;
	}
	return tmp;
}
D_m = abs(D)
NOTE: w0, M, D_m, h, l, and d should be sorted in increasing order before calling this function.
real(8) function code(w0, m, d_m, h, l, d)
    real(8), intent (in) :: w0
    real(8), intent (in) :: m
    real(8), intent (in) :: d_m
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: d
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = (d_m * (m * 0.5d0)) / d
    t_1 = w0 * sqrt((1.0d0 - (((0.5d0 * ((d_m * (m * h)) / d)) / l) * (d_m * ((m * 0.5d0) / d)))))
    if ((h / l) <= (-1d+264)) then
        tmp = t_1
    else if ((h / l) <= (-1d-95)) then
        tmp = w0 * sqrt((1.0d0 - (((h / l) * t_0) * t_0)))
    else
        tmp = t_1
    end if
    code = tmp
end function
D_m = Math.abs(D);
assert w0 < M && M < D_m && D_m < h && h < l && l < d;
public static double code(double w0, double M, double D_m, double h, double l, double d) {
	double t_0 = (D_m * (M * 0.5)) / d;
	double t_1 = w0 * Math.sqrt((1.0 - (((0.5 * ((D_m * (M * h)) / d)) / l) * (D_m * ((M * 0.5) / d)))));
	double tmp;
	if ((h / l) <= -1e+264) {
		tmp = t_1;
	} else if ((h / l) <= -1e-95) {
		tmp = w0 * Math.sqrt((1.0 - (((h / l) * t_0) * t_0)));
	} else {
		tmp = t_1;
	}
	return tmp;
}
D_m = math.fabs(D)
[w0, M, D_m, h, l, d] = sort([w0, M, D_m, h, l, d])
def code(w0, M, D_m, h, l, d):
	t_0 = (D_m * (M * 0.5)) / d
	t_1 = w0 * math.sqrt((1.0 - (((0.5 * ((D_m * (M * h)) / d)) / l) * (D_m * ((M * 0.5) / d)))))
	tmp = 0
	if (h / l) <= -1e+264:
		tmp = t_1
	elif (h / l) <= -1e-95:
		tmp = w0 * math.sqrt((1.0 - (((h / l) * t_0) * t_0)))
	else:
		tmp = t_1
	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)
	t_0 = Float64(Float64(D_m * Float64(M * 0.5)) / d)
	t_1 = Float64(w0 * sqrt(Float64(1.0 - Float64(Float64(Float64(0.5 * Float64(Float64(D_m * Float64(M * h)) / d)) / l) * Float64(D_m * Float64(Float64(M * 0.5) / d))))))
	tmp = 0.0
	if (Float64(h / l) <= -1e+264)
		tmp = t_1;
	elseif (Float64(h / l) <= -1e-95)
		tmp = Float64(w0 * sqrt(Float64(1.0 - Float64(Float64(Float64(h / l) * t_0) * t_0))));
	else
		tmp = t_1;
	end
	return tmp
end
D_m = abs(D);
w0, M, D_m, h, l, d = num2cell(sort([w0, M, D_m, h, l, d])){:}
function tmp_2 = code(w0, M, D_m, h, l, d)
	t_0 = (D_m * (M * 0.5)) / d;
	t_1 = w0 * sqrt((1.0 - (((0.5 * ((D_m * (M * h)) / d)) / l) * (D_m * ((M * 0.5) / d)))));
	tmp = 0.0;
	if ((h / l) <= -1e+264)
		tmp = t_1;
	elseif ((h / l) <= -1e-95)
		tmp = w0 * sqrt((1.0 - (((h / l) * t_0) * t_0)));
	else
		tmp = t_1;
	end
	tmp_2 = 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_] := Block[{t$95$0 = N[(N[(D$95$m * N[(M * 0.5), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]}, Block[{t$95$1 = N[(w0 * N[Sqrt[N[(1.0 - N[(N[(N[(0.5 * N[(N[(D$95$m * N[(M * h), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision] * N[(D$95$m * N[(N[(M * 0.5), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(h / l), $MachinePrecision], -1e+264], t$95$1, If[LessEqual[N[(h / l), $MachinePrecision], -1e-95], N[(w0 * N[Sqrt[N[(1.0 - N[(N[(N[(h / l), $MachinePrecision] * t$95$0), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], t$95$1]]]]
\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}
t_0 := \frac{D\_m \cdot \left(M \cdot 0.5\right)}{d}\\
t_1 := w0 \cdot \sqrt{1 - \frac{0.5 \cdot \frac{D\_m \cdot \left(M \cdot h\right)}{d}}{\ell} \cdot \left(D\_m \cdot \frac{M \cdot 0.5}{d}\right)}\\
\mathbf{if}\;\frac{h}{\ell} \leq -1 \cdot 10^{+264}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;\frac{h}{\ell} \leq -1 \cdot 10^{-95}:\\
\;\;\;\;w0 \cdot \sqrt{1 - \left(\frac{h}{\ell} \cdot t\_0\right) \cdot t\_0}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 h l) < -1.00000000000000004e264 or -9.99999999999999989e-96 < (/.f64 h l)

    1. Initial program 81.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\left(\frac{h}{\ell} \cdot \left(D \cdot \frac{M \cdot 0.5}{d}\right)\right) \cdot \left(D \cdot \frac{M \cdot 0.5}{d}\right)}} \]
    8. Step-by-step derivation
      1. associate-*l/93.5%

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

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

      \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\frac{h \cdot \left(D \cdot \frac{M}{\frac{d}{0.5}}\right)}{\ell}} \cdot \left(D \cdot \frac{M \cdot 0.5}{d}\right)} \]
    10. Taylor expanded in h around 0 90.1%

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

    if -1.00000000000000004e264 < (/.f64 h l) < -9.99999999999999989e-96

    1. Initial program 75.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 76.8% accurate, 1.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} t_0 := D\_m \cdot \frac{M \cdot 0.5}{d}\\ \mathbf{if}\;M \leq 4.1 \cdot 10^{-225}:\\ \;\;\;\;w0\\ \mathbf{else}:\\ \;\;\;\;w0 \cdot \sqrt{1 - \left(\frac{h}{\ell} \cdot t\_0\right) \cdot t\_0}\\ \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
 (let* ((t_0 (* D_m (/ (* M 0.5) d))))
   (if (<= M 4.1e-225) w0 (* w0 (sqrt (- 1.0 (* (* (/ h l) t_0) t_0)))))))
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 t_0 = D_m * ((M * 0.5) / d);
	double tmp;
	if (M <= 4.1e-225) {
		tmp = w0;
	} else {
		tmp = w0 * sqrt((1.0 - (((h / l) * t_0) * t_0)));
	}
	return tmp;
}
D_m = abs(D)
NOTE: w0, M, D_m, h, l, and d should be sorted in increasing order before calling this function.
real(8) function code(w0, m, d_m, h, l, d)
    real(8), intent (in) :: w0
    real(8), intent (in) :: m
    real(8), intent (in) :: d_m
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: d
    real(8) :: t_0
    real(8) :: tmp
    t_0 = d_m * ((m * 0.5d0) / d)
    if (m <= 4.1d-225) then
        tmp = w0
    else
        tmp = w0 * sqrt((1.0d0 - (((h / l) * t_0) * t_0)))
    end if
    code = tmp
end function
D_m = Math.abs(D);
assert w0 < M && M < D_m && D_m < h && h < l && l < d;
public static double code(double w0, double M, double D_m, double h, double l, double d) {
	double t_0 = D_m * ((M * 0.5) / d);
	double tmp;
	if (M <= 4.1e-225) {
		tmp = w0;
	} else {
		tmp = w0 * Math.sqrt((1.0 - (((h / l) * t_0) * t_0)));
	}
	return tmp;
}
D_m = math.fabs(D)
[w0, M, D_m, h, l, d] = sort([w0, M, D_m, h, l, d])
def code(w0, M, D_m, h, l, d):
	t_0 = D_m * ((M * 0.5) / d)
	tmp = 0
	if M <= 4.1e-225:
		tmp = w0
	else:
		tmp = w0 * math.sqrt((1.0 - (((h / l) * t_0) * t_0)))
	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)
	t_0 = Float64(D_m * Float64(Float64(M * 0.5) / d))
	tmp = 0.0
	if (M <= 4.1e-225)
		tmp = w0;
	else
		tmp = Float64(w0 * sqrt(Float64(1.0 - Float64(Float64(Float64(h / l) * t_0) * t_0))));
	end
	return tmp
end
D_m = abs(D);
w0, M, D_m, h, l, d = num2cell(sort([w0, M, D_m, h, l, d])){:}
function tmp_2 = code(w0, M, D_m, h, l, d)
	t_0 = D_m * ((M * 0.5) / d);
	tmp = 0.0;
	if (M <= 4.1e-225)
		tmp = w0;
	else
		tmp = w0 * sqrt((1.0 - (((h / l) * t_0) * t_0)));
	end
	tmp_2 = 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_] := Block[{t$95$0 = N[(D$95$m * N[(N[(M * 0.5), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[M, 4.1e-225], w0, N[(w0 * N[Sqrt[N[(1.0 - N[(N[(N[(h / l), $MachinePrecision] * t$95$0), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $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}
t_0 := D\_m \cdot \frac{M \cdot 0.5}{d}\\
\mathbf{if}\;M \leq 4.1 \cdot 10^{-225}:\\
\;\;\;\;w0\\

\mathbf{else}:\\
\;\;\;\;w0 \cdot \sqrt{1 - \left(\frac{h}{\ell} \cdot t\_0\right) \cdot t\_0}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if M < 4.10000000000000022e-225

    1. Initial program 78.0%

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

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

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

    if 4.10000000000000022e-225 < M

    1. Initial program 81.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 84.8% accurate, 1.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} t_0 := D\_m \cdot \frac{M \cdot 0.5}{d}\\ \mathbf{if}\;d \leq 10^{-45}:\\ \;\;\;\;w0 \cdot \sqrt{1 - \frac{h \cdot D\_m}{\ell \cdot \frac{d}{M \cdot 0.5}} \cdot t\_0}\\ \mathbf{else}:\\ \;\;\;\;w0 \cdot \sqrt{1 - \frac{0.5 \cdot \frac{D\_m \cdot \left(M \cdot h\right)}{d}}{\ell} \cdot t\_0}\\ \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
 (let* ((t_0 (* D_m (/ (* M 0.5) d))))
   (if (<= d 1e-45)
     (* w0 (sqrt (- 1.0 (* (/ (* h D_m) (* l (/ d (* M 0.5)))) t_0))))
     (* w0 (sqrt (- 1.0 (* (/ (* 0.5 (/ (* D_m (* M h)) d)) l) t_0)))))))
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 t_0 = D_m * ((M * 0.5) / d);
	double tmp;
	if (d <= 1e-45) {
		tmp = w0 * sqrt((1.0 - (((h * D_m) / (l * (d / (M * 0.5)))) * t_0)));
	} else {
		tmp = w0 * sqrt((1.0 - (((0.5 * ((D_m * (M * h)) / d)) / l) * t_0)));
	}
	return tmp;
}
D_m = abs(D)
NOTE: w0, M, D_m, h, l, and d should be sorted in increasing order before calling this function.
real(8) function code(w0, m, d_m, h, l, d)
    real(8), intent (in) :: w0
    real(8), intent (in) :: m
    real(8), intent (in) :: d_m
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: d
    real(8) :: t_0
    real(8) :: tmp
    t_0 = d_m * ((m * 0.5d0) / d)
    if (d <= 1d-45) then
        tmp = w0 * sqrt((1.0d0 - (((h * d_m) / (l * (d / (m * 0.5d0)))) * t_0)))
    else
        tmp = w0 * sqrt((1.0d0 - (((0.5d0 * ((d_m * (m * h)) / d)) / l) * t_0)))
    end if
    code = tmp
end function
D_m = Math.abs(D);
assert w0 < M && M < D_m && D_m < h && h < l && l < d;
public static double code(double w0, double M, double D_m, double h, double l, double d) {
	double t_0 = D_m * ((M * 0.5) / d);
	double tmp;
	if (d <= 1e-45) {
		tmp = w0 * Math.sqrt((1.0 - (((h * D_m) / (l * (d / (M * 0.5)))) * t_0)));
	} else {
		tmp = w0 * Math.sqrt((1.0 - (((0.5 * ((D_m * (M * h)) / d)) / l) * t_0)));
	}
	return tmp;
}
D_m = math.fabs(D)
[w0, M, D_m, h, l, d] = sort([w0, M, D_m, h, l, d])
def code(w0, M, D_m, h, l, d):
	t_0 = D_m * ((M * 0.5) / d)
	tmp = 0
	if d <= 1e-45:
		tmp = w0 * math.sqrt((1.0 - (((h * D_m) / (l * (d / (M * 0.5)))) * t_0)))
	else:
		tmp = w0 * math.sqrt((1.0 - (((0.5 * ((D_m * (M * h)) / d)) / l) * t_0)))
	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)
	t_0 = Float64(D_m * Float64(Float64(M * 0.5) / d))
	tmp = 0.0
	if (d <= 1e-45)
		tmp = Float64(w0 * sqrt(Float64(1.0 - Float64(Float64(Float64(h * D_m) / Float64(l * Float64(d / Float64(M * 0.5)))) * t_0))));
	else
		tmp = Float64(w0 * sqrt(Float64(1.0 - Float64(Float64(Float64(0.5 * Float64(Float64(D_m * Float64(M * h)) / d)) / l) * t_0))));
	end
	return tmp
end
D_m = abs(D);
w0, M, D_m, h, l, d = num2cell(sort([w0, M, D_m, h, l, d])){:}
function tmp_2 = code(w0, M, D_m, h, l, d)
	t_0 = D_m * ((M * 0.5) / d);
	tmp = 0.0;
	if (d <= 1e-45)
		tmp = w0 * sqrt((1.0 - (((h * D_m) / (l * (d / (M * 0.5)))) * t_0)));
	else
		tmp = w0 * sqrt((1.0 - (((0.5 * ((D_m * (M * h)) / d)) / l) * t_0)));
	end
	tmp_2 = 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_] := Block[{t$95$0 = N[(D$95$m * N[(N[(M * 0.5), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, 1e-45], N[(w0 * N[Sqrt[N[(1.0 - N[(N[(N[(h * D$95$m), $MachinePrecision] / N[(l * N[(d / N[(M * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(w0 * N[Sqrt[N[(1.0 - N[(N[(N[(0.5 * N[(N[(D$95$m * N[(M * h), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $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}
t_0 := D\_m \cdot \frac{M \cdot 0.5}{d}\\
\mathbf{if}\;d \leq 10^{-45}:\\
\;\;\;\;w0 \cdot \sqrt{1 - \frac{h \cdot D\_m}{\ell \cdot \frac{d}{M \cdot 0.5}} \cdot t\_0}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < 9.99999999999999984e-46

    1. Initial program 76.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto w0 \cdot \sqrt{1 - \left(\frac{h}{\ell} \cdot \color{blue}{\frac{D \cdot \left(M \cdot 0.5\right)}{d}}\right) \cdot \left(D \cdot \frac{M \cdot 0.5}{d}\right)} \]
    10. Step-by-step derivation
      1. associate-/l*78.1%

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

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

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

    if 9.99999999999999984e-46 < d

    1. Initial program 86.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\left(\frac{h}{\ell} \cdot \left(D \cdot \frac{M \cdot 0.5}{d}\right)\right) \cdot \left(D \cdot \frac{M \cdot 0.5}{d}\right)}} \]
    8. Step-by-step derivation
      1. associate-*l/92.3%

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

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

      \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\frac{h \cdot \left(D \cdot \frac{M}{\frac{d}{0.5}}\right)}{\ell}} \cdot \left(D \cdot \frac{M \cdot 0.5}{d}\right)} \]
    10. Taylor expanded in h around 0 88.3%

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

Alternative 5: 68.7% accurate, 216.0× 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])\\ \\ w0 \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 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) {
	return w0;
}
D_m = abs(D)
NOTE: w0, M, D_m, h, l, and d should be sorted in increasing order before calling this function.
real(8) function code(w0, m, d_m, h, l, d)
    real(8), intent (in) :: w0
    real(8), intent (in) :: m
    real(8), intent (in) :: d_m
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: d
    code = w0
end function
D_m = Math.abs(D);
assert w0 < M && M < D_m && D_m < h && h < l && l < d;
public static double code(double w0, double M, double D_m, double h, double l, double d) {
	return w0;
}
D_m = math.fabs(D)
[w0, M, D_m, h, l, d] = sort([w0, M, D_m, h, l, d])
def code(w0, M, D_m, h, l, d):
	return w0
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)
	return w0
end
D_m = abs(D);
w0, M, D_m, h, l, d = num2cell(sort([w0, M, D_m, h, l, d])){:}
function tmp = code(w0, M, D_m, h, l, d)
	tmp = w0;
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_] := w0
\begin{array}{l}
D_m = \left|D\right|
\\
[w0, M, D_m, h, l, d] = \mathsf{sort}([w0, M, D_m, h, l, d])\\
\\
w0
\end{array}
Derivation
  1. Initial program 79.5%

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

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

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

Reproduce

?
herbie shell --seed 2024034 -o generate:simplify
(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))))))