Henrywood and Agarwal, Equation (9a)

Percentage Accurate: 80.7% → 88.2%
Time: 16.2s
Alternatives: 8
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 8 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: 80.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \end{array} \]
(FPCore (w0 M D h l d)
 :precision binary64
 (* w0 (sqrt (- 1.0 (* (pow (/ (* M D) (* 2.0 d)) 2.0) (/ h l))))))
double code(double w0, double M, double D, double h, double l, double d) {
	return w0 * sqrt((1.0 - (pow(((M * D) / (2.0 * d)), 2.0) * (h / l))));
}
real(8) function code(w0, m, d, h, l, d_1)
    real(8), intent (in) :: w0
    real(8), intent (in) :: m
    real(8), intent (in) :: d
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: d_1
    code = w0 * sqrt((1.0d0 - ((((m * d) / (2.0d0 * d_1)) ** 2.0d0) * (h / l))))
end function
public static double code(double w0, double M, double D, double h, double l, double d) {
	return w0 * Math.sqrt((1.0 - (Math.pow(((M * D) / (2.0 * d)), 2.0) * (h / l))));
}
def code(w0, M, D, h, l, d):
	return w0 * math.sqrt((1.0 - (math.pow(((M * D) / (2.0 * d)), 2.0) * (h / l))))
function code(w0, M, D, h, l, d)
	return Float64(w0 * sqrt(Float64(1.0 - Float64((Float64(Float64(M * D) / Float64(2.0 * d)) ^ 2.0) * Float64(h / l)))))
end
function tmp = code(w0, M, D, h, l, d)
	tmp = w0 * sqrt((1.0 - ((((M * D) / (2.0 * d)) ^ 2.0) * (h / l))));
end
code[w0_, M_, D_, h_, l_, d_] := N[(w0 * N[Sqrt[N[(1.0 - N[(N[Power[N[(N[(M * D), $MachinePrecision] / N[(2.0 * d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}}
\end{array}

Alternative 1: 88.2% accurate, 0.3× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ w0_m = \left|w0\right| \\ w0_s = \mathsf{copysign}\left(1, w0\right) \\ [w0_m, M_m, D_m, h, l, d] = \mathsf{sort}([w0_m, M_m, D_m, h, l, d])\\ \\ \begin{array}{l} t_0 := {\left(\frac{M_m \cdot D_m}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}\\ w0_s \cdot \begin{array}{l} \mathbf{if}\;t_0 \leq -\infty:\\ \;\;\;\;{\left(\sqrt{w0_m} \cdot e^{0.25 \cdot \left(\left(2 \cdot \log M_m + \log \left(-0.25 \cdot \frac{h}{\ell \cdot {d}^{2}}\right)\right) + -2 \cdot \log \left(\frac{1}{D_m}\right)\right)}\right)}^{2}\\ \mathbf{elif}\;t_0 \leq 0:\\ \;\;\;\;w0_m \cdot \sqrt{1 - \frac{h}{\ell} \cdot {\left(D_m \cdot \frac{M_m}{2 \cdot d}\right)}^{2}}\\ \mathbf{else}:\\ \;\;\;\;w0_m \cdot \sqrt{1 - \left(0.5 \cdot \frac{D_m \cdot \left(M_m \cdot h\right)}{d \cdot \ell}\right) \cdot \frac{D_m \cdot 0.5}{\frac{d}{M_m}}}\\ \end{array} \end{array} \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
w0_m = (fabs.f64 w0)
w0_s = (copysign.f64 1 w0)
NOTE: w0_m, M_m, D_m, h, l, and d should be sorted in increasing order before calling this function.
(FPCore (w0_s w0_m M_m D_m h l d)
 :precision binary64
 (let* ((t_0 (* (pow (/ (* M_m D_m) (* 2.0 d)) 2.0) (/ h l))))
   (*
    w0_s
    (if (<= t_0 (- INFINITY))
      (pow
       (*
        (sqrt w0_m)
        (exp
         (*
          0.25
          (+
           (+ (* 2.0 (log M_m)) (log (* -0.25 (/ h (* l (pow d 2.0))))))
           (* -2.0 (log (/ 1.0 D_m)))))))
       2.0)
      (if (<= t_0 0.0)
        (* w0_m (sqrt (- 1.0 (* (/ h l) (pow (* D_m (/ M_m (* 2.0 d))) 2.0)))))
        (*
         w0_m
         (sqrt
          (-
           1.0
           (*
            (* 0.5 (/ (* D_m (* M_m h)) (* d l)))
            (/ (* D_m 0.5) (/ d M_m)))))))))))
M_m = fabs(M);
D_m = fabs(D);
w0_m = fabs(w0);
w0_s = copysign(1.0, w0);
assert(w0_m < M_m && M_m < D_m && D_m < h && h < l && l < d);
double code(double w0_s, double w0_m, double M_m, double D_m, double h, double l, double d) {
	double t_0 = pow(((M_m * D_m) / (2.0 * d)), 2.0) * (h / l);
	double tmp;
	if (t_0 <= -((double) INFINITY)) {
		tmp = pow((sqrt(w0_m) * exp((0.25 * (((2.0 * log(M_m)) + log((-0.25 * (h / (l * pow(d, 2.0)))))) + (-2.0 * log((1.0 / D_m))))))), 2.0);
	} else if (t_0 <= 0.0) {
		tmp = w0_m * sqrt((1.0 - ((h / l) * pow((D_m * (M_m / (2.0 * d))), 2.0))));
	} else {
		tmp = w0_m * sqrt((1.0 - ((0.5 * ((D_m * (M_m * h)) / (d * l))) * ((D_m * 0.5) / (d / M_m)))));
	}
	return w0_s * tmp;
}
M_m = Math.abs(M);
D_m = Math.abs(D);
w0_m = Math.abs(w0);
w0_s = Math.copySign(1.0, w0);
assert w0_m < M_m && M_m < D_m && D_m < h && h < l && l < d;
public static double code(double w0_s, double w0_m, double M_m, double D_m, double h, double l, double d) {
	double t_0 = Math.pow(((M_m * D_m) / (2.0 * d)), 2.0) * (h / l);
	double tmp;
	if (t_0 <= -Double.POSITIVE_INFINITY) {
		tmp = Math.pow((Math.sqrt(w0_m) * Math.exp((0.25 * (((2.0 * Math.log(M_m)) + Math.log((-0.25 * (h / (l * Math.pow(d, 2.0)))))) + (-2.0 * Math.log((1.0 / D_m))))))), 2.0);
	} else if (t_0 <= 0.0) {
		tmp = w0_m * Math.sqrt((1.0 - ((h / l) * Math.pow((D_m * (M_m / (2.0 * d))), 2.0))));
	} else {
		tmp = w0_m * Math.sqrt((1.0 - ((0.5 * ((D_m * (M_m * h)) / (d * l))) * ((D_m * 0.5) / (d / M_m)))));
	}
	return w0_s * tmp;
}
M_m = math.fabs(M)
D_m = math.fabs(D)
w0_m = math.fabs(w0)
w0_s = math.copysign(1.0, w0)
[w0_m, M_m, D_m, h, l, d] = sort([w0_m, M_m, D_m, h, l, d])
def code(w0_s, w0_m, M_m, D_m, h, l, d):
	t_0 = math.pow(((M_m * D_m) / (2.0 * d)), 2.0) * (h / l)
	tmp = 0
	if t_0 <= -math.inf:
		tmp = math.pow((math.sqrt(w0_m) * math.exp((0.25 * (((2.0 * math.log(M_m)) + math.log((-0.25 * (h / (l * math.pow(d, 2.0)))))) + (-2.0 * math.log((1.0 / D_m))))))), 2.0)
	elif t_0 <= 0.0:
		tmp = w0_m * math.sqrt((1.0 - ((h / l) * math.pow((D_m * (M_m / (2.0 * d))), 2.0))))
	else:
		tmp = w0_m * math.sqrt((1.0 - ((0.5 * ((D_m * (M_m * h)) / (d * l))) * ((D_m * 0.5) / (d / M_m)))))
	return w0_s * tmp
M_m = abs(M)
D_m = abs(D)
w0_m = abs(w0)
w0_s = copysign(1.0, w0)
w0_m, M_m, D_m, h, l, d = sort([w0_m, M_m, D_m, h, l, d])
function code(w0_s, w0_m, M_m, D_m, h, l, d)
	t_0 = Float64((Float64(Float64(M_m * D_m) / Float64(2.0 * d)) ^ 2.0) * Float64(h / l))
	tmp = 0.0
	if (t_0 <= Float64(-Inf))
		tmp = Float64(sqrt(w0_m) * exp(Float64(0.25 * Float64(Float64(Float64(2.0 * log(M_m)) + log(Float64(-0.25 * Float64(h / Float64(l * (d ^ 2.0)))))) + Float64(-2.0 * log(Float64(1.0 / D_m))))))) ^ 2.0;
	elseif (t_0 <= 0.0)
		tmp = Float64(w0_m * sqrt(Float64(1.0 - Float64(Float64(h / l) * (Float64(D_m * Float64(M_m / Float64(2.0 * d))) ^ 2.0)))));
	else
		tmp = Float64(w0_m * sqrt(Float64(1.0 - Float64(Float64(0.5 * Float64(Float64(D_m * Float64(M_m * h)) / Float64(d * l))) * Float64(Float64(D_m * 0.5) / Float64(d / M_m))))));
	end
	return Float64(w0_s * tmp)
end
M_m = abs(M);
D_m = abs(D);
w0_m = abs(w0);
w0_s = sign(w0) * abs(1.0);
w0_m, M_m, D_m, h, l, d = num2cell(sort([w0_m, M_m, D_m, h, l, d])){:}
function tmp_2 = code(w0_s, w0_m, M_m, D_m, h, l, d)
	t_0 = (((M_m * D_m) / (2.0 * d)) ^ 2.0) * (h / l);
	tmp = 0.0;
	if (t_0 <= -Inf)
		tmp = (sqrt(w0_m) * exp((0.25 * (((2.0 * log(M_m)) + log((-0.25 * (h / (l * (d ^ 2.0)))))) + (-2.0 * log((1.0 / D_m))))))) ^ 2.0;
	elseif (t_0 <= 0.0)
		tmp = w0_m * sqrt((1.0 - ((h / l) * ((D_m * (M_m / (2.0 * d))) ^ 2.0))));
	else
		tmp = w0_m * sqrt((1.0 - ((0.5 * ((D_m * (M_m * h)) / (d * l))) * ((D_m * 0.5) / (d / M_m)))));
	end
	tmp_2 = w0_s * tmp;
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
w0_m = N[Abs[w0], $MachinePrecision]
w0_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[w0]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: w0_m, M_m, D_m, h, l, and d should be sorted in increasing order before calling this function.
code[w0$95$s_, w0$95$m_, M$95$m_, D$95$m_, h_, l_, d_] := Block[{t$95$0 = N[(N[Power[N[(N[(M$95$m * D$95$m), $MachinePrecision] / N[(2.0 * d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]}, N[(w0$95$s * If[LessEqual[t$95$0, (-Infinity)], N[Power[N[(N[Sqrt[w0$95$m], $MachinePrecision] * N[Exp[N[(0.25 * N[(N[(N[(2.0 * N[Log[M$95$m], $MachinePrecision]), $MachinePrecision] + N[Log[N[(-0.25 * N[(h / N[(l * N[Power[d, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + N[(-2.0 * N[Log[N[(1.0 / D$95$m), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision], If[LessEqual[t$95$0, 0.0], N[(w0$95$m * N[Sqrt[N[(1.0 - N[(N[(h / l), $MachinePrecision] * N[Power[N[(D$95$m * N[(M$95$m / N[(2.0 * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(w0$95$m * N[Sqrt[N[(1.0 - N[(N[(0.5 * N[(N[(D$95$m * N[(M$95$m * h), $MachinePrecision]), $MachinePrecision] / N[(d * l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[(D$95$m * 0.5), $MachinePrecision] / N[(d / M$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]), $MachinePrecision]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
w0_m = \left|w0\right|
\\
w0_s = \mathsf{copysign}\left(1, w0\right)
\\
[w0_m, M_m, D_m, h, l, d] = \mathsf{sort}([w0_m, M_m, D_m, h, l, d])\\
\\
\begin{array}{l}
t_0 := {\left(\frac{M_m \cdot D_m}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}\\
w0_s \cdot \begin{array}{l}
\mathbf{if}\;t_0 \leq -\infty:\\
\;\;\;\;{\left(\sqrt{w0_m} \cdot e^{0.25 \cdot \left(\left(2 \cdot \log M_m + \log \left(-0.25 \cdot \frac{h}{\ell \cdot {d}^{2}}\right)\right) + -2 \cdot \log \left(\frac{1}{D_m}\right)\right)}\right)}^{2}\\

\mathbf{elif}\;t_0 \leq 0:\\
\;\;\;\;w0_m \cdot \sqrt{1 - \frac{h}{\ell} \cdot {\left(D_m \cdot \frac{M_m}{2 \cdot d}\right)}^{2}}\\

\mathbf{else}:\\
\;\;\;\;w0_m \cdot \sqrt{1 - \left(0.5 \cdot \frac{D_m \cdot \left(M_m \cdot h\right)}{d \cdot \ell}\right) \cdot \frac{D_m \cdot 0.5}{\frac{d}{M_m}}}\\


\end{array}
\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 2: 81.0% accurate, 0.3× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ w0_m = \left|w0\right| \\ w0_s = \mathsf{copysign}\left(1, w0\right) \\ [w0_m, M_m, D_m, h, l, d] = \mathsf{sort}([w0_m, M_m, D_m, h, l, d])\\ \\ \begin{array}{l} t_0 := {\left(\frac{M_m \cdot D_m}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}\\ w0_s \cdot \begin{array}{l} \mathbf{if}\;t_0 \leq -\infty:\\ \;\;\;\;{\left(\sqrt{w0_m} \cdot e^{0.25 \cdot \left(\log \left(-0.25 \cdot \frac{{\left(M_m \cdot D_m\right)}^{2}}{\frac{\ell}{h}}\right) + -2 \cdot \log d\right)}\right)}^{2}\\ \mathbf{elif}\;t_0 \leq 0:\\ \;\;\;\;w0_m \cdot \sqrt{1 - \frac{h}{\ell} \cdot {\left(D_m \cdot \frac{M_m}{2 \cdot d}\right)}^{2}}\\ \mathbf{else}:\\ \;\;\;\;w0_m \cdot \sqrt{1 - \left(0.5 \cdot \frac{D_m \cdot \left(M_m \cdot h\right)}{d \cdot \ell}\right) \cdot \frac{D_m \cdot 0.5}{\frac{d}{M_m}}}\\ \end{array} \end{array} \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
w0_m = (fabs.f64 w0)
w0_s = (copysign.f64 1 w0)
NOTE: w0_m, M_m, D_m, h, l, and d should be sorted in increasing order before calling this function.
(FPCore (w0_s w0_m M_m D_m h l d)
 :precision binary64
 (let* ((t_0 (* (pow (/ (* M_m D_m) (* 2.0 d)) 2.0) (/ h l))))
   (*
    w0_s
    (if (<= t_0 (- INFINITY))
      (pow
       (*
        (sqrt w0_m)
        (exp
         (*
          0.25
          (+
           (log (* -0.25 (/ (pow (* M_m D_m) 2.0) (/ l h))))
           (* -2.0 (log d))))))
       2.0)
      (if (<= t_0 0.0)
        (* w0_m (sqrt (- 1.0 (* (/ h l) (pow (* D_m (/ M_m (* 2.0 d))) 2.0)))))
        (*
         w0_m
         (sqrt
          (-
           1.0
           (*
            (* 0.5 (/ (* D_m (* M_m h)) (* d l)))
            (/ (* D_m 0.5) (/ d M_m)))))))))))
M_m = fabs(M);
D_m = fabs(D);
w0_m = fabs(w0);
w0_s = copysign(1.0, w0);
assert(w0_m < M_m && M_m < D_m && D_m < h && h < l && l < d);
double code(double w0_s, double w0_m, double M_m, double D_m, double h, double l, double d) {
	double t_0 = pow(((M_m * D_m) / (2.0 * d)), 2.0) * (h / l);
	double tmp;
	if (t_0 <= -((double) INFINITY)) {
		tmp = pow((sqrt(w0_m) * exp((0.25 * (log((-0.25 * (pow((M_m * D_m), 2.0) / (l / h)))) + (-2.0 * log(d)))))), 2.0);
	} else if (t_0 <= 0.0) {
		tmp = w0_m * sqrt((1.0 - ((h / l) * pow((D_m * (M_m / (2.0 * d))), 2.0))));
	} else {
		tmp = w0_m * sqrt((1.0 - ((0.5 * ((D_m * (M_m * h)) / (d * l))) * ((D_m * 0.5) / (d / M_m)))));
	}
	return w0_s * tmp;
}
M_m = Math.abs(M);
D_m = Math.abs(D);
w0_m = Math.abs(w0);
w0_s = Math.copySign(1.0, w0);
assert w0_m < M_m && M_m < D_m && D_m < h && h < l && l < d;
public static double code(double w0_s, double w0_m, double M_m, double D_m, double h, double l, double d) {
	double t_0 = Math.pow(((M_m * D_m) / (2.0 * d)), 2.0) * (h / l);
	double tmp;
	if (t_0 <= -Double.POSITIVE_INFINITY) {
		tmp = Math.pow((Math.sqrt(w0_m) * Math.exp((0.25 * (Math.log((-0.25 * (Math.pow((M_m * D_m), 2.0) / (l / h)))) + (-2.0 * Math.log(d)))))), 2.0);
	} else if (t_0 <= 0.0) {
		tmp = w0_m * Math.sqrt((1.0 - ((h / l) * Math.pow((D_m * (M_m / (2.0 * d))), 2.0))));
	} else {
		tmp = w0_m * Math.sqrt((1.0 - ((0.5 * ((D_m * (M_m * h)) / (d * l))) * ((D_m * 0.5) / (d / M_m)))));
	}
	return w0_s * tmp;
}
M_m = math.fabs(M)
D_m = math.fabs(D)
w0_m = math.fabs(w0)
w0_s = math.copysign(1.0, w0)
[w0_m, M_m, D_m, h, l, d] = sort([w0_m, M_m, D_m, h, l, d])
def code(w0_s, w0_m, M_m, D_m, h, l, d):
	t_0 = math.pow(((M_m * D_m) / (2.0 * d)), 2.0) * (h / l)
	tmp = 0
	if t_0 <= -math.inf:
		tmp = math.pow((math.sqrt(w0_m) * math.exp((0.25 * (math.log((-0.25 * (math.pow((M_m * D_m), 2.0) / (l / h)))) + (-2.0 * math.log(d)))))), 2.0)
	elif t_0 <= 0.0:
		tmp = w0_m * math.sqrt((1.0 - ((h / l) * math.pow((D_m * (M_m / (2.0 * d))), 2.0))))
	else:
		tmp = w0_m * math.sqrt((1.0 - ((0.5 * ((D_m * (M_m * h)) / (d * l))) * ((D_m * 0.5) / (d / M_m)))))
	return w0_s * tmp
M_m = abs(M)
D_m = abs(D)
w0_m = abs(w0)
w0_s = copysign(1.0, w0)
w0_m, M_m, D_m, h, l, d = sort([w0_m, M_m, D_m, h, l, d])
function code(w0_s, w0_m, M_m, D_m, h, l, d)
	t_0 = Float64((Float64(Float64(M_m * D_m) / Float64(2.0 * d)) ^ 2.0) * Float64(h / l))
	tmp = 0.0
	if (t_0 <= Float64(-Inf))
		tmp = Float64(sqrt(w0_m) * exp(Float64(0.25 * Float64(log(Float64(-0.25 * Float64((Float64(M_m * D_m) ^ 2.0) / Float64(l / h)))) + Float64(-2.0 * log(d)))))) ^ 2.0;
	elseif (t_0 <= 0.0)
		tmp = Float64(w0_m * sqrt(Float64(1.0 - Float64(Float64(h / l) * (Float64(D_m * Float64(M_m / Float64(2.0 * d))) ^ 2.0)))));
	else
		tmp = Float64(w0_m * sqrt(Float64(1.0 - Float64(Float64(0.5 * Float64(Float64(D_m * Float64(M_m * h)) / Float64(d * l))) * Float64(Float64(D_m * 0.5) / Float64(d / M_m))))));
	end
	return Float64(w0_s * tmp)
end
M_m = abs(M);
D_m = abs(D);
w0_m = abs(w0);
w0_s = sign(w0) * abs(1.0);
w0_m, M_m, D_m, h, l, d = num2cell(sort([w0_m, M_m, D_m, h, l, d])){:}
function tmp_2 = code(w0_s, w0_m, M_m, D_m, h, l, d)
	t_0 = (((M_m * D_m) / (2.0 * d)) ^ 2.0) * (h / l);
	tmp = 0.0;
	if (t_0 <= -Inf)
		tmp = (sqrt(w0_m) * exp((0.25 * (log((-0.25 * (((M_m * D_m) ^ 2.0) / (l / h)))) + (-2.0 * log(d)))))) ^ 2.0;
	elseif (t_0 <= 0.0)
		tmp = w0_m * sqrt((1.0 - ((h / l) * ((D_m * (M_m / (2.0 * d))) ^ 2.0))));
	else
		tmp = w0_m * sqrt((1.0 - ((0.5 * ((D_m * (M_m * h)) / (d * l))) * ((D_m * 0.5) / (d / M_m)))));
	end
	tmp_2 = w0_s * tmp;
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
w0_m = N[Abs[w0], $MachinePrecision]
w0_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[w0]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: w0_m, M_m, D_m, h, l, and d should be sorted in increasing order before calling this function.
code[w0$95$s_, w0$95$m_, M$95$m_, D$95$m_, h_, l_, d_] := Block[{t$95$0 = N[(N[Power[N[(N[(M$95$m * D$95$m), $MachinePrecision] / N[(2.0 * d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]}, N[(w0$95$s * If[LessEqual[t$95$0, (-Infinity)], N[Power[N[(N[Sqrt[w0$95$m], $MachinePrecision] * N[Exp[N[(0.25 * N[(N[Log[N[(-0.25 * N[(N[Power[N[(M$95$m * D$95$m), $MachinePrecision], 2.0], $MachinePrecision] / N[(l / h), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + N[(-2.0 * N[Log[d], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision], If[LessEqual[t$95$0, 0.0], N[(w0$95$m * N[Sqrt[N[(1.0 - N[(N[(h / l), $MachinePrecision] * N[Power[N[(D$95$m * N[(M$95$m / N[(2.0 * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(w0$95$m * N[Sqrt[N[(1.0 - N[(N[(0.5 * N[(N[(D$95$m * N[(M$95$m * h), $MachinePrecision]), $MachinePrecision] / N[(d * l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[(D$95$m * 0.5), $MachinePrecision] / N[(d / M$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]), $MachinePrecision]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
w0_m = \left|w0\right|
\\
w0_s = \mathsf{copysign}\left(1, w0\right)
\\
[w0_m, M_m, D_m, h, l, d] = \mathsf{sort}([w0_m, M_m, D_m, h, l, d])\\
\\
\begin{array}{l}
t_0 := {\left(\frac{M_m \cdot D_m}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}\\
w0_s \cdot \begin{array}{l}
\mathbf{if}\;t_0 \leq -\infty:\\
\;\;\;\;{\left(\sqrt{w0_m} \cdot e^{0.25 \cdot \left(\log \left(-0.25 \cdot \frac{{\left(M_m \cdot D_m\right)}^{2}}{\frac{\ell}{h}}\right) + -2 \cdot \log d\right)}\right)}^{2}\\

\mathbf{elif}\;t_0 \leq 0:\\
\;\;\;\;w0_m \cdot \sqrt{1 - \frac{h}{\ell} \cdot {\left(D_m \cdot \frac{M_m}{2 \cdot d}\right)}^{2}}\\

\mathbf{else}:\\
\;\;\;\;w0_m \cdot \sqrt{1 - \left(0.5 \cdot \frac{D_m \cdot \left(M_m \cdot h\right)}{d \cdot \ell}\right) \cdot \frac{D_m \cdot 0.5}{\frac{d}{M_m}}}\\


\end{array}
\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 3: 87.7% accurate, 0.7× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ w0_m = \left|w0\right| \\ w0_s = \mathsf{copysign}\left(1, w0\right) \\ [w0_m, M_m, D_m, h, l, d] = \mathsf{sort}([w0_m, M_m, D_m, h, l, d])\\ \\ w0_s \cdot \begin{array}{l} \mathbf{if}\;1 - {\left(\frac{M_m \cdot D_m}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell} \leq 2 \cdot 10^{+267}:\\ \;\;\;\;w0_m \cdot \sqrt{1 - \frac{h}{\ell} \cdot {\left(D_m \cdot \frac{M_m}{2 \cdot d}\right)}^{2}}\\ \mathbf{else}:\\ \;\;\;\;w0_m \cdot \sqrt{1 - \left(0.5 \cdot \frac{D_m \cdot \left(M_m \cdot h\right)}{d \cdot \ell}\right) \cdot \frac{D_m \cdot 0.5}{\frac{d}{M_m}}}\\ \end{array} \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
w0_m = (fabs.f64 w0)
w0_s = (copysign.f64 1 w0)
NOTE: w0_m, M_m, D_m, h, l, and d should be sorted in increasing order before calling this function.
(FPCore (w0_s w0_m M_m D_m h l d)
 :precision binary64
 (*
  w0_s
  (if (<= (- 1.0 (* (pow (/ (* M_m D_m) (* 2.0 d)) 2.0) (/ h l))) 2e+267)
    (* w0_m (sqrt (- 1.0 (* (/ h l) (pow (* D_m (/ M_m (* 2.0 d))) 2.0)))))
    (*
     w0_m
     (sqrt
      (-
       1.0
       (*
        (* 0.5 (/ (* D_m (* M_m h)) (* d l)))
        (/ (* D_m 0.5) (/ d M_m)))))))))
M_m = fabs(M);
D_m = fabs(D);
w0_m = fabs(w0);
w0_s = copysign(1.0, w0);
assert(w0_m < M_m && M_m < D_m && D_m < h && h < l && l < d);
double code(double w0_s, double w0_m, double M_m, double D_m, double h, double l, double d) {
	double tmp;
	if ((1.0 - (pow(((M_m * D_m) / (2.0 * d)), 2.0) * (h / l))) <= 2e+267) {
		tmp = w0_m * sqrt((1.0 - ((h / l) * pow((D_m * (M_m / (2.0 * d))), 2.0))));
	} else {
		tmp = w0_m * sqrt((1.0 - ((0.5 * ((D_m * (M_m * h)) / (d * l))) * ((D_m * 0.5) / (d / M_m)))));
	}
	return w0_s * tmp;
}
M_m = abs(M)
D_m = abs(D)
w0_m = abs(w0)
w0_s = copysign(1.0d0, w0)
NOTE: w0_m, M_m, D_m, h, l, and d should be sorted in increasing order before calling this function.
real(8) function code(w0_s, w0_m, m_m, d_m, h, l, d)
    real(8), intent (in) :: w0_s
    real(8), intent (in) :: w0_m
    real(8), intent (in) :: m_m
    real(8), intent (in) :: d_m
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: d
    real(8) :: tmp
    if ((1.0d0 - ((((m_m * d_m) / (2.0d0 * d)) ** 2.0d0) * (h / l))) <= 2d+267) then
        tmp = w0_m * sqrt((1.0d0 - ((h / l) * ((d_m * (m_m / (2.0d0 * d))) ** 2.0d0))))
    else
        tmp = w0_m * sqrt((1.0d0 - ((0.5d0 * ((d_m * (m_m * h)) / (d * l))) * ((d_m * 0.5d0) / (d / m_m)))))
    end if
    code = w0_s * tmp
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
w0_m = Math.abs(w0);
w0_s = Math.copySign(1.0, w0);
assert w0_m < M_m && M_m < D_m && D_m < h && h < l && l < d;
public static double code(double w0_s, double w0_m, double M_m, double D_m, double h, double l, double d) {
	double tmp;
	if ((1.0 - (Math.pow(((M_m * D_m) / (2.0 * d)), 2.0) * (h / l))) <= 2e+267) {
		tmp = w0_m * Math.sqrt((1.0 - ((h / l) * Math.pow((D_m * (M_m / (2.0 * d))), 2.0))));
	} else {
		tmp = w0_m * Math.sqrt((1.0 - ((0.5 * ((D_m * (M_m * h)) / (d * l))) * ((D_m * 0.5) / (d / M_m)))));
	}
	return w0_s * tmp;
}
M_m = math.fabs(M)
D_m = math.fabs(D)
w0_m = math.fabs(w0)
w0_s = math.copysign(1.0, w0)
[w0_m, M_m, D_m, h, l, d] = sort([w0_m, M_m, D_m, h, l, d])
def code(w0_s, w0_m, M_m, D_m, h, l, d):
	tmp = 0
	if (1.0 - (math.pow(((M_m * D_m) / (2.0 * d)), 2.0) * (h / l))) <= 2e+267:
		tmp = w0_m * math.sqrt((1.0 - ((h / l) * math.pow((D_m * (M_m / (2.0 * d))), 2.0))))
	else:
		tmp = w0_m * math.sqrt((1.0 - ((0.5 * ((D_m * (M_m * h)) / (d * l))) * ((D_m * 0.5) / (d / M_m)))))
	return w0_s * tmp
M_m = abs(M)
D_m = abs(D)
w0_m = abs(w0)
w0_s = copysign(1.0, w0)
w0_m, M_m, D_m, h, l, d = sort([w0_m, M_m, D_m, h, l, d])
function code(w0_s, w0_m, M_m, D_m, h, l, d)
	tmp = 0.0
	if (Float64(1.0 - Float64((Float64(Float64(M_m * D_m) / Float64(2.0 * d)) ^ 2.0) * Float64(h / l))) <= 2e+267)
		tmp = Float64(w0_m * sqrt(Float64(1.0 - Float64(Float64(h / l) * (Float64(D_m * Float64(M_m / Float64(2.0 * d))) ^ 2.0)))));
	else
		tmp = Float64(w0_m * sqrt(Float64(1.0 - Float64(Float64(0.5 * Float64(Float64(D_m * Float64(M_m * h)) / Float64(d * l))) * Float64(Float64(D_m * 0.5) / Float64(d / M_m))))));
	end
	return Float64(w0_s * tmp)
end
M_m = abs(M);
D_m = abs(D);
w0_m = abs(w0);
w0_s = sign(w0) * abs(1.0);
w0_m, M_m, D_m, h, l, d = num2cell(sort([w0_m, M_m, D_m, h, l, d])){:}
function tmp_2 = code(w0_s, w0_m, M_m, D_m, h, l, d)
	tmp = 0.0;
	if ((1.0 - ((((M_m * D_m) / (2.0 * d)) ^ 2.0) * (h / l))) <= 2e+267)
		tmp = w0_m * sqrt((1.0 - ((h / l) * ((D_m * (M_m / (2.0 * d))) ^ 2.0))));
	else
		tmp = w0_m * sqrt((1.0 - ((0.5 * ((D_m * (M_m * h)) / (d * l))) * ((D_m * 0.5) / (d / M_m)))));
	end
	tmp_2 = w0_s * tmp;
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
w0_m = N[Abs[w0], $MachinePrecision]
w0_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[w0]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: w0_m, M_m, D_m, h, l, and d should be sorted in increasing order before calling this function.
code[w0$95$s_, w0$95$m_, M$95$m_, D$95$m_, h_, l_, d_] := N[(w0$95$s * If[LessEqual[N[(1.0 - N[(N[Power[N[(N[(M$95$m * D$95$m), $MachinePrecision] / N[(2.0 * d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2e+267], N[(w0$95$m * N[Sqrt[N[(1.0 - N[(N[(h / l), $MachinePrecision] * N[Power[N[(D$95$m * N[(M$95$m / N[(2.0 * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(w0$95$m * N[Sqrt[N[(1.0 - N[(N[(0.5 * N[(N[(D$95$m * N[(M$95$m * h), $MachinePrecision]), $MachinePrecision] / N[(d * l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[(D$95$m * 0.5), $MachinePrecision] / N[(d / M$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
w0_m = \left|w0\right|
\\
w0_s = \mathsf{copysign}\left(1, w0\right)
\\
[w0_m, M_m, D_m, h, l, d] = \mathsf{sort}([w0_m, M_m, D_m, h, l, d])\\
\\
w0_s \cdot \begin{array}{l}
\mathbf{if}\;1 - {\left(\frac{M_m \cdot D_m}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell} \leq 2 \cdot 10^{+267}:\\
\;\;\;\;w0_m \cdot \sqrt{1 - \frac{h}{\ell} \cdot {\left(D_m \cdot \frac{M_m}{2 \cdot d}\right)}^{2}}\\

\mathbf{else}:\\
\;\;\;\;w0_m \cdot \sqrt{1 - \left(0.5 \cdot \frac{D_m \cdot \left(M_m \cdot h\right)}{d \cdot \ell}\right) \cdot \frac{D_m \cdot 0.5}{\frac{d}{M_m}}}\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 4: 86.9% accurate, 1.6× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ w0_m = \left|w0\right| \\ w0_s = \mathsf{copysign}\left(1, w0\right) \\ [w0_m, M_m, D_m, h, l, d] = \mathsf{sort}([w0_m, M_m, D_m, h, l, d])\\ \\ \begin{array}{l} t_0 := 0.5 \cdot \frac{D_m \cdot \left(M_m \cdot h\right)}{d \cdot \ell}\\ t_1 := M_m \cdot \frac{0.5}{\frac{d}{D_m}}\\ w0_s \cdot \begin{array}{l} \mathbf{if}\;\frac{h}{\ell} \leq -\infty:\\ \;\;\;\;w0_m \cdot \sqrt{1 - t_0 \cdot t_1}\\ \mathbf{elif}\;\frac{h}{\ell} \leq -4 \cdot 10^{-77}:\\ \;\;\;\;w0_m \cdot \sqrt{1 - t_1 \cdot \left(\frac{h}{\ell} \cdot t_1\right)}\\ \mathbf{else}:\\ \;\;\;\;w0_m \cdot \sqrt{1 - t_0 \cdot \frac{D_m \cdot 0.5}{\frac{d}{M_m}}}\\ \end{array} \end{array} \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
w0_m = (fabs.f64 w0)
w0_s = (copysign.f64 1 w0)
NOTE: w0_m, M_m, D_m, h, l, and d should be sorted in increasing order before calling this function.
(FPCore (w0_s w0_m M_m D_m h l d)
 :precision binary64
 (let* ((t_0 (* 0.5 (/ (* D_m (* M_m h)) (* d l))))
        (t_1 (* M_m (/ 0.5 (/ d D_m)))))
   (*
    w0_s
    (if (<= (/ h l) (- INFINITY))
      (* w0_m (sqrt (- 1.0 (* t_0 t_1))))
      (if (<= (/ h l) -4e-77)
        (* w0_m (sqrt (- 1.0 (* t_1 (* (/ h l) t_1)))))
        (* w0_m (sqrt (- 1.0 (* t_0 (/ (* D_m 0.5) (/ d M_m)))))))))))
M_m = fabs(M);
D_m = fabs(D);
w0_m = fabs(w0);
w0_s = copysign(1.0, w0);
assert(w0_m < M_m && M_m < D_m && D_m < h && h < l && l < d);
double code(double w0_s, double w0_m, double M_m, double D_m, double h, double l, double d) {
	double t_0 = 0.5 * ((D_m * (M_m * h)) / (d * l));
	double t_1 = M_m * (0.5 / (d / D_m));
	double tmp;
	if ((h / l) <= -((double) INFINITY)) {
		tmp = w0_m * sqrt((1.0 - (t_0 * t_1)));
	} else if ((h / l) <= -4e-77) {
		tmp = w0_m * sqrt((1.0 - (t_1 * ((h / l) * t_1))));
	} else {
		tmp = w0_m * sqrt((1.0 - (t_0 * ((D_m * 0.5) / (d / M_m)))));
	}
	return w0_s * tmp;
}
M_m = Math.abs(M);
D_m = Math.abs(D);
w0_m = Math.abs(w0);
w0_s = Math.copySign(1.0, w0);
assert w0_m < M_m && M_m < D_m && D_m < h && h < l && l < d;
public static double code(double w0_s, double w0_m, double M_m, double D_m, double h, double l, double d) {
	double t_0 = 0.5 * ((D_m * (M_m * h)) / (d * l));
	double t_1 = M_m * (0.5 / (d / D_m));
	double tmp;
	if ((h / l) <= -Double.POSITIVE_INFINITY) {
		tmp = w0_m * Math.sqrt((1.0 - (t_0 * t_1)));
	} else if ((h / l) <= -4e-77) {
		tmp = w0_m * Math.sqrt((1.0 - (t_1 * ((h / l) * t_1))));
	} else {
		tmp = w0_m * Math.sqrt((1.0 - (t_0 * ((D_m * 0.5) / (d / M_m)))));
	}
	return w0_s * tmp;
}
M_m = math.fabs(M)
D_m = math.fabs(D)
w0_m = math.fabs(w0)
w0_s = math.copysign(1.0, w0)
[w0_m, M_m, D_m, h, l, d] = sort([w0_m, M_m, D_m, h, l, d])
def code(w0_s, w0_m, M_m, D_m, h, l, d):
	t_0 = 0.5 * ((D_m * (M_m * h)) / (d * l))
	t_1 = M_m * (0.5 / (d / D_m))
	tmp = 0
	if (h / l) <= -math.inf:
		tmp = w0_m * math.sqrt((1.0 - (t_0 * t_1)))
	elif (h / l) <= -4e-77:
		tmp = w0_m * math.sqrt((1.0 - (t_1 * ((h / l) * t_1))))
	else:
		tmp = w0_m * math.sqrt((1.0 - (t_0 * ((D_m * 0.5) / (d / M_m)))))
	return w0_s * tmp
M_m = abs(M)
D_m = abs(D)
w0_m = abs(w0)
w0_s = copysign(1.0, w0)
w0_m, M_m, D_m, h, l, d = sort([w0_m, M_m, D_m, h, l, d])
function code(w0_s, w0_m, M_m, D_m, h, l, d)
	t_0 = Float64(0.5 * Float64(Float64(D_m * Float64(M_m * h)) / Float64(d * l)))
	t_1 = Float64(M_m * Float64(0.5 / Float64(d / D_m)))
	tmp = 0.0
	if (Float64(h / l) <= Float64(-Inf))
		tmp = Float64(w0_m * sqrt(Float64(1.0 - Float64(t_0 * t_1))));
	elseif (Float64(h / l) <= -4e-77)
		tmp = Float64(w0_m * sqrt(Float64(1.0 - Float64(t_1 * Float64(Float64(h / l) * t_1)))));
	else
		tmp = Float64(w0_m * sqrt(Float64(1.0 - Float64(t_0 * Float64(Float64(D_m * 0.5) / Float64(d / M_m))))));
	end
	return Float64(w0_s * tmp)
end
M_m = abs(M);
D_m = abs(D);
w0_m = abs(w0);
w0_s = sign(w0) * abs(1.0);
w0_m, M_m, D_m, h, l, d = num2cell(sort([w0_m, M_m, D_m, h, l, d])){:}
function tmp_2 = code(w0_s, w0_m, M_m, D_m, h, l, d)
	t_0 = 0.5 * ((D_m * (M_m * h)) / (d * l));
	t_1 = M_m * (0.5 / (d / D_m));
	tmp = 0.0;
	if ((h / l) <= -Inf)
		tmp = w0_m * sqrt((1.0 - (t_0 * t_1)));
	elseif ((h / l) <= -4e-77)
		tmp = w0_m * sqrt((1.0 - (t_1 * ((h / l) * t_1))));
	else
		tmp = w0_m * sqrt((1.0 - (t_0 * ((D_m * 0.5) / (d / M_m)))));
	end
	tmp_2 = w0_s * tmp;
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
w0_m = N[Abs[w0], $MachinePrecision]
w0_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[w0]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: w0_m, M_m, D_m, h, l, and d should be sorted in increasing order before calling this function.
code[w0$95$s_, w0$95$m_, M$95$m_, D$95$m_, h_, l_, d_] := Block[{t$95$0 = N[(0.5 * N[(N[(D$95$m * N[(M$95$m * h), $MachinePrecision]), $MachinePrecision] / N[(d * l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(M$95$m * N[(0.5 / N[(d / D$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(w0$95$s * If[LessEqual[N[(h / l), $MachinePrecision], (-Infinity)], N[(w0$95$m * N[Sqrt[N[(1.0 - N[(t$95$0 * t$95$1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(h / l), $MachinePrecision], -4e-77], N[(w0$95$m * N[Sqrt[N[(1.0 - N[(t$95$1 * N[(N[(h / l), $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(w0$95$m * N[Sqrt[N[(1.0 - N[(t$95$0 * N[(N[(D$95$m * 0.5), $MachinePrecision] / N[(d / M$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]), $MachinePrecision]]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
w0_m = \left|w0\right|
\\
w0_s = \mathsf{copysign}\left(1, w0\right)
\\
[w0_m, M_m, D_m, h, l, d] = \mathsf{sort}([w0_m, M_m, D_m, h, l, d])\\
\\
\begin{array}{l}
t_0 := 0.5 \cdot \frac{D_m \cdot \left(M_m \cdot h\right)}{d \cdot \ell}\\
t_1 := M_m \cdot \frac{0.5}{\frac{d}{D_m}}\\
w0_s \cdot \begin{array}{l}
\mathbf{if}\;\frac{h}{\ell} \leq -\infty:\\
\;\;\;\;w0_m \cdot \sqrt{1 - t_0 \cdot t_1}\\

\mathbf{elif}\;\frac{h}{\ell} \leq -4 \cdot 10^{-77}:\\
\;\;\;\;w0_m \cdot \sqrt{1 - t_1 \cdot \left(\frac{h}{\ell} \cdot t_1\right)}\\

\mathbf{else}:\\
\;\;\;\;w0_m \cdot \sqrt{1 - t_0 \cdot \frac{D_m \cdot 0.5}{\frac{d}{M_m}}}\\


\end{array}
\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 5: 87.0% accurate, 1.6× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ w0_m = \left|w0\right| \\ w0_s = \mathsf{copysign}\left(1, w0\right) \\ [w0_m, M_m, D_m, h, l, d] = \mathsf{sort}([w0_m, M_m, D_m, h, l, d])\\ \\ \begin{array}{l} t_0 := 0.5 \cdot \frac{D_m \cdot \left(M_m \cdot h\right)}{d \cdot \ell}\\ t_1 := \frac{M_m \cdot 0.5}{\frac{d}{D_m}}\\ w0_s \cdot \begin{array}{l} \mathbf{if}\;\frac{h}{\ell} \leq -\infty:\\ \;\;\;\;w0_m \cdot \sqrt{1 - t_0 \cdot \left(M_m \cdot \frac{0.5}{\frac{d}{D_m}}\right)}\\ \mathbf{elif}\;\frac{h}{\ell} \leq -4 \cdot 10^{-77}:\\ \;\;\;\;w0_m \cdot \sqrt{1 - t_1 \cdot \frac{t_1}{\frac{\ell}{h}}}\\ \mathbf{else}:\\ \;\;\;\;w0_m \cdot \sqrt{1 - t_0 \cdot \frac{D_m \cdot 0.5}{\frac{d}{M_m}}}\\ \end{array} \end{array} \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
w0_m = (fabs.f64 w0)
w0_s = (copysign.f64 1 w0)
NOTE: w0_m, M_m, D_m, h, l, and d should be sorted in increasing order before calling this function.
(FPCore (w0_s w0_m M_m D_m h l d)
 :precision binary64
 (let* ((t_0 (* 0.5 (/ (* D_m (* M_m h)) (* d l))))
        (t_1 (/ (* M_m 0.5) (/ d D_m))))
   (*
    w0_s
    (if (<= (/ h l) (- INFINITY))
      (* w0_m (sqrt (- 1.0 (* t_0 (* M_m (/ 0.5 (/ d D_m)))))))
      (if (<= (/ h l) -4e-77)
        (* w0_m (sqrt (- 1.0 (* t_1 (/ t_1 (/ l h))))))
        (* w0_m (sqrt (- 1.0 (* t_0 (/ (* D_m 0.5) (/ d M_m)))))))))))
M_m = fabs(M);
D_m = fabs(D);
w0_m = fabs(w0);
w0_s = copysign(1.0, w0);
assert(w0_m < M_m && M_m < D_m && D_m < h && h < l && l < d);
double code(double w0_s, double w0_m, double M_m, double D_m, double h, double l, double d) {
	double t_0 = 0.5 * ((D_m * (M_m * h)) / (d * l));
	double t_1 = (M_m * 0.5) / (d / D_m);
	double tmp;
	if ((h / l) <= -((double) INFINITY)) {
		tmp = w0_m * sqrt((1.0 - (t_0 * (M_m * (0.5 / (d / D_m))))));
	} else if ((h / l) <= -4e-77) {
		tmp = w0_m * sqrt((1.0 - (t_1 * (t_1 / (l / h)))));
	} else {
		tmp = w0_m * sqrt((1.0 - (t_0 * ((D_m * 0.5) / (d / M_m)))));
	}
	return w0_s * tmp;
}
M_m = Math.abs(M);
D_m = Math.abs(D);
w0_m = Math.abs(w0);
w0_s = Math.copySign(1.0, w0);
assert w0_m < M_m && M_m < D_m && D_m < h && h < l && l < d;
public static double code(double w0_s, double w0_m, double M_m, double D_m, double h, double l, double d) {
	double t_0 = 0.5 * ((D_m * (M_m * h)) / (d * l));
	double t_1 = (M_m * 0.5) / (d / D_m);
	double tmp;
	if ((h / l) <= -Double.POSITIVE_INFINITY) {
		tmp = w0_m * Math.sqrt((1.0 - (t_0 * (M_m * (0.5 / (d / D_m))))));
	} else if ((h / l) <= -4e-77) {
		tmp = w0_m * Math.sqrt((1.0 - (t_1 * (t_1 / (l / h)))));
	} else {
		tmp = w0_m * Math.sqrt((1.0 - (t_0 * ((D_m * 0.5) / (d / M_m)))));
	}
	return w0_s * tmp;
}
M_m = math.fabs(M)
D_m = math.fabs(D)
w0_m = math.fabs(w0)
w0_s = math.copysign(1.0, w0)
[w0_m, M_m, D_m, h, l, d] = sort([w0_m, M_m, D_m, h, l, d])
def code(w0_s, w0_m, M_m, D_m, h, l, d):
	t_0 = 0.5 * ((D_m * (M_m * h)) / (d * l))
	t_1 = (M_m * 0.5) / (d / D_m)
	tmp = 0
	if (h / l) <= -math.inf:
		tmp = w0_m * math.sqrt((1.0 - (t_0 * (M_m * (0.5 / (d / D_m))))))
	elif (h / l) <= -4e-77:
		tmp = w0_m * math.sqrt((1.0 - (t_1 * (t_1 / (l / h)))))
	else:
		tmp = w0_m * math.sqrt((1.0 - (t_0 * ((D_m * 0.5) / (d / M_m)))))
	return w0_s * tmp
M_m = abs(M)
D_m = abs(D)
w0_m = abs(w0)
w0_s = copysign(1.0, w0)
w0_m, M_m, D_m, h, l, d = sort([w0_m, M_m, D_m, h, l, d])
function code(w0_s, w0_m, M_m, D_m, h, l, d)
	t_0 = Float64(0.5 * Float64(Float64(D_m * Float64(M_m * h)) / Float64(d * l)))
	t_1 = Float64(Float64(M_m * 0.5) / Float64(d / D_m))
	tmp = 0.0
	if (Float64(h / l) <= Float64(-Inf))
		tmp = Float64(w0_m * sqrt(Float64(1.0 - Float64(t_0 * Float64(M_m * Float64(0.5 / Float64(d / D_m)))))));
	elseif (Float64(h / l) <= -4e-77)
		tmp = Float64(w0_m * sqrt(Float64(1.0 - Float64(t_1 * Float64(t_1 / Float64(l / h))))));
	else
		tmp = Float64(w0_m * sqrt(Float64(1.0 - Float64(t_0 * Float64(Float64(D_m * 0.5) / Float64(d / M_m))))));
	end
	return Float64(w0_s * tmp)
end
M_m = abs(M);
D_m = abs(D);
w0_m = abs(w0);
w0_s = sign(w0) * abs(1.0);
w0_m, M_m, D_m, h, l, d = num2cell(sort([w0_m, M_m, D_m, h, l, d])){:}
function tmp_2 = code(w0_s, w0_m, M_m, D_m, h, l, d)
	t_0 = 0.5 * ((D_m * (M_m * h)) / (d * l));
	t_1 = (M_m * 0.5) / (d / D_m);
	tmp = 0.0;
	if ((h / l) <= -Inf)
		tmp = w0_m * sqrt((1.0 - (t_0 * (M_m * (0.5 / (d / D_m))))));
	elseif ((h / l) <= -4e-77)
		tmp = w0_m * sqrt((1.0 - (t_1 * (t_1 / (l / h)))));
	else
		tmp = w0_m * sqrt((1.0 - (t_0 * ((D_m * 0.5) / (d / M_m)))));
	end
	tmp_2 = w0_s * tmp;
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
w0_m = N[Abs[w0], $MachinePrecision]
w0_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[w0]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: w0_m, M_m, D_m, h, l, and d should be sorted in increasing order before calling this function.
code[w0$95$s_, w0$95$m_, M$95$m_, D$95$m_, h_, l_, d_] := Block[{t$95$0 = N[(0.5 * N[(N[(D$95$m * N[(M$95$m * h), $MachinePrecision]), $MachinePrecision] / N[(d * l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(M$95$m * 0.5), $MachinePrecision] / N[(d / D$95$m), $MachinePrecision]), $MachinePrecision]}, N[(w0$95$s * If[LessEqual[N[(h / l), $MachinePrecision], (-Infinity)], N[(w0$95$m * N[Sqrt[N[(1.0 - N[(t$95$0 * N[(M$95$m * N[(0.5 / N[(d / D$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(h / l), $MachinePrecision], -4e-77], N[(w0$95$m * N[Sqrt[N[(1.0 - N[(t$95$1 * N[(t$95$1 / N[(l / h), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(w0$95$m * N[Sqrt[N[(1.0 - N[(t$95$0 * N[(N[(D$95$m * 0.5), $MachinePrecision] / N[(d / M$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]), $MachinePrecision]]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
w0_m = \left|w0\right|
\\
w0_s = \mathsf{copysign}\left(1, w0\right)
\\
[w0_m, M_m, D_m, h, l, d] = \mathsf{sort}([w0_m, M_m, D_m, h, l, d])\\
\\
\begin{array}{l}
t_0 := 0.5 \cdot \frac{D_m \cdot \left(M_m \cdot h\right)}{d \cdot \ell}\\
t_1 := \frac{M_m \cdot 0.5}{\frac{d}{D_m}}\\
w0_s \cdot \begin{array}{l}
\mathbf{if}\;\frac{h}{\ell} \leq -\infty:\\
\;\;\;\;w0_m \cdot \sqrt{1 - t_0 \cdot \left(M_m \cdot \frac{0.5}{\frac{d}{D_m}}\right)}\\

\mathbf{elif}\;\frac{h}{\ell} \leq -4 \cdot 10^{-77}:\\
\;\;\;\;w0_m \cdot \sqrt{1 - t_1 \cdot \frac{t_1}{\frac{\ell}{h}}}\\

\mathbf{else}:\\
\;\;\;\;w0_m \cdot \sqrt{1 - t_0 \cdot \frac{D_m \cdot 0.5}{\frac{d}{M_m}}}\\


\end{array}
\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 6: 83.5% accurate, 1.7× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ w0_m = \left|w0\right| \\ w0_s = \mathsf{copysign}\left(1, w0\right) \\ [w0_m, M_m, D_m, h, l, d] = \mathsf{sort}([w0_m, M_m, D_m, h, l, d])\\ \\ w0_s \cdot \begin{array}{l} \mathbf{if}\;M_m \leq 1.32 \cdot 10^{-225}:\\ \;\;\;\;w0_m\\ \mathbf{else}:\\ \;\;\;\;w0_m \cdot \sqrt{1 - \left(0.5 \cdot \frac{D_m \cdot \left(M_m \cdot h\right)}{d \cdot \ell}\right) \cdot \left(M_m \cdot \frac{0.5}{\frac{d}{D_m}}\right)}\\ \end{array} \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
w0_m = (fabs.f64 w0)
w0_s = (copysign.f64 1 w0)
NOTE: w0_m, M_m, D_m, h, l, and d should be sorted in increasing order before calling this function.
(FPCore (w0_s w0_m M_m D_m h l d)
 :precision binary64
 (*
  w0_s
  (if (<= M_m 1.32e-225)
    w0_m
    (*
     w0_m
     (sqrt
      (-
       1.0
       (*
        (* 0.5 (/ (* D_m (* M_m h)) (* d l)))
        (* M_m (/ 0.5 (/ d D_m))))))))))
M_m = fabs(M);
D_m = fabs(D);
w0_m = fabs(w0);
w0_s = copysign(1.0, w0);
assert(w0_m < M_m && M_m < D_m && D_m < h && h < l && l < d);
double code(double w0_s, double w0_m, double M_m, double D_m, double h, double l, double d) {
	double tmp;
	if (M_m <= 1.32e-225) {
		tmp = w0_m;
	} else {
		tmp = w0_m * sqrt((1.0 - ((0.5 * ((D_m * (M_m * h)) / (d * l))) * (M_m * (0.5 / (d / D_m))))));
	}
	return w0_s * tmp;
}
M_m = abs(M)
D_m = abs(D)
w0_m = abs(w0)
w0_s = copysign(1.0d0, w0)
NOTE: w0_m, M_m, D_m, h, l, and d should be sorted in increasing order before calling this function.
real(8) function code(w0_s, w0_m, m_m, d_m, h, l, d)
    real(8), intent (in) :: w0_s
    real(8), intent (in) :: w0_m
    real(8), intent (in) :: m_m
    real(8), intent (in) :: d_m
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: d
    real(8) :: tmp
    if (m_m <= 1.32d-225) then
        tmp = w0_m
    else
        tmp = w0_m * sqrt((1.0d0 - ((0.5d0 * ((d_m * (m_m * h)) / (d * l))) * (m_m * (0.5d0 / (d / d_m))))))
    end if
    code = w0_s * tmp
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
w0_m = Math.abs(w0);
w0_s = Math.copySign(1.0, w0);
assert w0_m < M_m && M_m < D_m && D_m < h && h < l && l < d;
public static double code(double w0_s, double w0_m, double M_m, double D_m, double h, double l, double d) {
	double tmp;
	if (M_m <= 1.32e-225) {
		tmp = w0_m;
	} else {
		tmp = w0_m * Math.sqrt((1.0 - ((0.5 * ((D_m * (M_m * h)) / (d * l))) * (M_m * (0.5 / (d / D_m))))));
	}
	return w0_s * tmp;
}
M_m = math.fabs(M)
D_m = math.fabs(D)
w0_m = math.fabs(w0)
w0_s = math.copysign(1.0, w0)
[w0_m, M_m, D_m, h, l, d] = sort([w0_m, M_m, D_m, h, l, d])
def code(w0_s, w0_m, M_m, D_m, h, l, d):
	tmp = 0
	if M_m <= 1.32e-225:
		tmp = w0_m
	else:
		tmp = w0_m * math.sqrt((1.0 - ((0.5 * ((D_m * (M_m * h)) / (d * l))) * (M_m * (0.5 / (d / D_m))))))
	return w0_s * tmp
M_m = abs(M)
D_m = abs(D)
w0_m = abs(w0)
w0_s = copysign(1.0, w0)
w0_m, M_m, D_m, h, l, d = sort([w0_m, M_m, D_m, h, l, d])
function code(w0_s, w0_m, M_m, D_m, h, l, d)
	tmp = 0.0
	if (M_m <= 1.32e-225)
		tmp = w0_m;
	else
		tmp = Float64(w0_m * sqrt(Float64(1.0 - Float64(Float64(0.5 * Float64(Float64(D_m * Float64(M_m * h)) / Float64(d * l))) * Float64(M_m * Float64(0.5 / Float64(d / D_m)))))));
	end
	return Float64(w0_s * tmp)
end
M_m = abs(M);
D_m = abs(D);
w0_m = abs(w0);
w0_s = sign(w0) * abs(1.0);
w0_m, M_m, D_m, h, l, d = num2cell(sort([w0_m, M_m, D_m, h, l, d])){:}
function tmp_2 = code(w0_s, w0_m, M_m, D_m, h, l, d)
	tmp = 0.0;
	if (M_m <= 1.32e-225)
		tmp = w0_m;
	else
		tmp = w0_m * sqrt((1.0 - ((0.5 * ((D_m * (M_m * h)) / (d * l))) * (M_m * (0.5 / (d / D_m))))));
	end
	tmp_2 = w0_s * tmp;
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
w0_m = N[Abs[w0], $MachinePrecision]
w0_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[w0]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: w0_m, M_m, D_m, h, l, and d should be sorted in increasing order before calling this function.
code[w0$95$s_, w0$95$m_, M$95$m_, D$95$m_, h_, l_, d_] := N[(w0$95$s * If[LessEqual[M$95$m, 1.32e-225], w0$95$m, N[(w0$95$m * N[Sqrt[N[(1.0 - N[(N[(0.5 * N[(N[(D$95$m * N[(M$95$m * h), $MachinePrecision]), $MachinePrecision] / N[(d * l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(M$95$m * N[(0.5 / N[(d / D$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
w0_m = \left|w0\right|
\\
w0_s = \mathsf{copysign}\left(1, w0\right)
\\
[w0_m, M_m, D_m, h, l, d] = \mathsf{sort}([w0_m, M_m, D_m, h, l, d])\\
\\
w0_s \cdot \begin{array}{l}
\mathbf{if}\;M_m \leq 1.32 \cdot 10^{-225}:\\
\;\;\;\;w0_m\\

\mathbf{else}:\\
\;\;\;\;w0_m \cdot \sqrt{1 - \left(0.5 \cdot \frac{D_m \cdot \left(M_m \cdot h\right)}{d \cdot \ell}\right) \cdot \left(M_m \cdot \frac{0.5}{\frac{d}{D_m}}\right)}\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 7: 83.8% accurate, 1.8× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ w0_m = \left|w0\right| \\ w0_s = \mathsf{copysign}\left(1, w0\right) \\ [w0_m, M_m, D_m, h, l, d] = \mathsf{sort}([w0_m, M_m, D_m, h, l, d])\\ \\ w0_s \cdot \left(w0_m \cdot \sqrt{1 - \left(0.5 \cdot \frac{D_m \cdot \left(M_m \cdot h\right)}{d \cdot \ell}\right) \cdot \frac{D_m \cdot 0.5}{\frac{d}{M_m}}}\right) \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
w0_m = (fabs.f64 w0)
w0_s = (copysign.f64 1 w0)
NOTE: w0_m, M_m, D_m, h, l, and d should be sorted in increasing order before calling this function.
(FPCore (w0_s w0_m M_m D_m h l d)
 :precision binary64
 (*
  w0_s
  (*
   w0_m
   (sqrt
    (-
     1.0
     (* (* 0.5 (/ (* D_m (* M_m h)) (* d l))) (/ (* D_m 0.5) (/ d M_m))))))))
M_m = fabs(M);
D_m = fabs(D);
w0_m = fabs(w0);
w0_s = copysign(1.0, w0);
assert(w0_m < M_m && M_m < D_m && D_m < h && h < l && l < d);
double code(double w0_s, double w0_m, double M_m, double D_m, double h, double l, double d) {
	return w0_s * (w0_m * sqrt((1.0 - ((0.5 * ((D_m * (M_m * h)) / (d * l))) * ((D_m * 0.5) / (d / M_m))))));
}
M_m = abs(M)
D_m = abs(D)
w0_m = abs(w0)
w0_s = copysign(1.0d0, w0)
NOTE: w0_m, M_m, D_m, h, l, and d should be sorted in increasing order before calling this function.
real(8) function code(w0_s, w0_m, m_m, d_m, h, l, d)
    real(8), intent (in) :: w0_s
    real(8), intent (in) :: w0_m
    real(8), intent (in) :: m_m
    real(8), intent (in) :: d_m
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: d
    code = w0_s * (w0_m * sqrt((1.0d0 - ((0.5d0 * ((d_m * (m_m * h)) / (d * l))) * ((d_m * 0.5d0) / (d / m_m))))))
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
w0_m = Math.abs(w0);
w0_s = Math.copySign(1.0, w0);
assert w0_m < M_m && M_m < D_m && D_m < h && h < l && l < d;
public static double code(double w0_s, double w0_m, double M_m, double D_m, double h, double l, double d) {
	return w0_s * (w0_m * Math.sqrt((1.0 - ((0.5 * ((D_m * (M_m * h)) / (d * l))) * ((D_m * 0.5) / (d / M_m))))));
}
M_m = math.fabs(M)
D_m = math.fabs(D)
w0_m = math.fabs(w0)
w0_s = math.copysign(1.0, w0)
[w0_m, M_m, D_m, h, l, d] = sort([w0_m, M_m, D_m, h, l, d])
def code(w0_s, w0_m, M_m, D_m, h, l, d):
	return w0_s * (w0_m * math.sqrt((1.0 - ((0.5 * ((D_m * (M_m * h)) / (d * l))) * ((D_m * 0.5) / (d / M_m))))))
M_m = abs(M)
D_m = abs(D)
w0_m = abs(w0)
w0_s = copysign(1.0, w0)
w0_m, M_m, D_m, h, l, d = sort([w0_m, M_m, D_m, h, l, d])
function code(w0_s, w0_m, M_m, D_m, h, l, d)
	return Float64(w0_s * Float64(w0_m * sqrt(Float64(1.0 - Float64(Float64(0.5 * Float64(Float64(D_m * Float64(M_m * h)) / Float64(d * l))) * Float64(Float64(D_m * 0.5) / Float64(d / M_m)))))))
end
M_m = abs(M);
D_m = abs(D);
w0_m = abs(w0);
w0_s = sign(w0) * abs(1.0);
w0_m, M_m, D_m, h, l, d = num2cell(sort([w0_m, M_m, D_m, h, l, d])){:}
function tmp = code(w0_s, w0_m, M_m, D_m, h, l, d)
	tmp = w0_s * (w0_m * sqrt((1.0 - ((0.5 * ((D_m * (M_m * h)) / (d * l))) * ((D_m * 0.5) / (d / M_m))))));
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
w0_m = N[Abs[w0], $MachinePrecision]
w0_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[w0]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: w0_m, M_m, D_m, h, l, and d should be sorted in increasing order before calling this function.
code[w0$95$s_, w0$95$m_, M$95$m_, D$95$m_, h_, l_, d_] := N[(w0$95$s * N[(w0$95$m * N[Sqrt[N[(1.0 - N[(N[(0.5 * N[(N[(D$95$m * N[(M$95$m * h), $MachinePrecision]), $MachinePrecision] / N[(d * l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[(D$95$m * 0.5), $MachinePrecision] / N[(d / M$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
w0_m = \left|w0\right|
\\
w0_s = \mathsf{copysign}\left(1, w0\right)
\\
[w0_m, M_m, D_m, h, l, d] = \mathsf{sort}([w0_m, M_m, D_m, h, l, d])\\
\\
w0_s \cdot \left(w0_m \cdot \sqrt{1 - \left(0.5 \cdot \frac{D_m \cdot \left(M_m \cdot h\right)}{d \cdot \ell}\right) \cdot \frac{D_m \cdot 0.5}{\frac{d}{M_m}}}\right)
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 8: 68.0% accurate, 216.0× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ w0_m = \left|w0\right| \\ w0_s = \mathsf{copysign}\left(1, w0\right) \\ [w0_m, M_m, D_m, h, l, d] = \mathsf{sort}([w0_m, M_m, D_m, h, l, d])\\ \\ w0_s \cdot w0_m \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
w0_m = (fabs.f64 w0)
w0_s = (copysign.f64 1 w0)
NOTE: w0_m, M_m, D_m, h, l, and d should be sorted in increasing order before calling this function.
(FPCore (w0_s w0_m M_m D_m h l d) :precision binary64 (* w0_s w0_m))
M_m = fabs(M);
D_m = fabs(D);
w0_m = fabs(w0);
w0_s = copysign(1.0, w0);
assert(w0_m < M_m && M_m < D_m && D_m < h && h < l && l < d);
double code(double w0_s, double w0_m, double M_m, double D_m, double h, double l, double d) {
	return w0_s * w0_m;
}
M_m = abs(M)
D_m = abs(D)
w0_m = abs(w0)
w0_s = copysign(1.0d0, w0)
NOTE: w0_m, M_m, D_m, h, l, and d should be sorted in increasing order before calling this function.
real(8) function code(w0_s, w0_m, m_m, d_m, h, l, d)
    real(8), intent (in) :: w0_s
    real(8), intent (in) :: w0_m
    real(8), intent (in) :: m_m
    real(8), intent (in) :: d_m
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: d
    code = w0_s * w0_m
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
w0_m = Math.abs(w0);
w0_s = Math.copySign(1.0, w0);
assert w0_m < M_m && M_m < D_m && D_m < h && h < l && l < d;
public static double code(double w0_s, double w0_m, double M_m, double D_m, double h, double l, double d) {
	return w0_s * w0_m;
}
M_m = math.fabs(M)
D_m = math.fabs(D)
w0_m = math.fabs(w0)
w0_s = math.copysign(1.0, w0)
[w0_m, M_m, D_m, h, l, d] = sort([w0_m, M_m, D_m, h, l, d])
def code(w0_s, w0_m, M_m, D_m, h, l, d):
	return w0_s * w0_m
M_m = abs(M)
D_m = abs(D)
w0_m = abs(w0)
w0_s = copysign(1.0, w0)
w0_m, M_m, D_m, h, l, d = sort([w0_m, M_m, D_m, h, l, d])
function code(w0_s, w0_m, M_m, D_m, h, l, d)
	return Float64(w0_s * w0_m)
end
M_m = abs(M);
D_m = abs(D);
w0_m = abs(w0);
w0_s = sign(w0) * abs(1.0);
w0_m, M_m, D_m, h, l, d = num2cell(sort([w0_m, M_m, D_m, h, l, d])){:}
function tmp = code(w0_s, w0_m, M_m, D_m, h, l, d)
	tmp = w0_s * w0_m;
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
w0_m = N[Abs[w0], $MachinePrecision]
w0_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[w0]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: w0_m, M_m, D_m, h, l, and d should be sorted in increasing order before calling this function.
code[w0$95$s_, w0$95$m_, M$95$m_, D$95$m_, h_, l_, d_] := N[(w0$95$s * w0$95$m), $MachinePrecision]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
w0_m = \left|w0\right|
\\
w0_s = \mathsf{copysign}\left(1, w0\right)
\\
[w0_m, M_m, D_m, h, l, d] = \mathsf{sort}([w0_m, M_m, D_m, h, l, d])\\
\\
w0_s \cdot w0_m
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Reproduce

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