Henrywood and Agarwal, Equation (9a)

Percentage Accurate: 80.7% → 88.2%
Time: 16.8s
Alternatives: 5
Speedup: 1.7×

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: 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| \\ 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_m] = \mathsf{sort}([w0_m, M_m, D_m, h, l, d_m])\\ \\ \begin{array}{l} t_0 := \frac{M\_m \cdot D\_m}{2 \cdot d\_m}\\ t_1 := M\_m \cdot \frac{D\_m \cdot 0.5}{d\_m}\\ w0\_s \cdot \begin{array}{l} \mathbf{if}\;t\_0 \leq 10^{-54}:\\ \;\;\;\;w0\_m \cdot \sqrt{1 - \frac{h \cdot \left(t\_1 \cdot t\_1\right)}{\ell}}\\ \mathbf{elif}\;t\_0 \leq 4 \cdot 10^{+144}:\\ \;\;\;\;w0\_m \cdot \sqrt{1 - \left(t\_0 \cdot \left(D\_m \cdot \frac{M\_m \cdot 0.5}{d\_m}\right)\right) \cdot \frac{h}{\ell}}\\ \mathbf{else}:\\ \;\;\;\;{\left(\sqrt{w0\_m} \cdot {\left(e^{0.25}\right)}^{\left(\log \left(-0.25 \cdot \frac{h \cdot {\left(M\_m \cdot D\_m\right)}^{2}}{\ell}\right) + -2 \cdot \log d\_m\right)}\right)}^{2}\\ \end{array} \end{array} \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
d_m = (fabs.f64 d)
w0\_m = (fabs.f64 w0)
w0\_s = (copysign.f64 #s(literal 1 binary64) w0)
NOTE: w0_m, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
(FPCore (w0_s w0_m M_m D_m h l d_m)
 :precision binary64
 (let* ((t_0 (/ (* M_m D_m) (* 2.0 d_m))) (t_1 (* M_m (/ (* D_m 0.5) d_m))))
   (*
    w0_s
    (if (<= t_0 1e-54)
      (* w0_m (sqrt (- 1.0 (/ (* h (* t_1 t_1)) l))))
      (if (<= t_0 4e+144)
        (* w0_m (sqrt (- 1.0 (* (* t_0 (* D_m (/ (* M_m 0.5) d_m))) (/ h l)))))
        (pow
         (*
          (sqrt w0_m)
          (pow
           (exp 0.25)
           (+
            (log (* -0.25 (/ (* h (pow (* M_m D_m) 2.0)) l)))
            (* -2.0 (log d_m)))))
         2.0))))))
M_m = fabs(M);
D_m = fabs(D);
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_m);
double code(double w0_s, double w0_m, double M_m, double D_m, double h, double l, double d_m) {
	double t_0 = (M_m * D_m) / (2.0 * d_m);
	double t_1 = M_m * ((D_m * 0.5) / d_m);
	double tmp;
	if (t_0 <= 1e-54) {
		tmp = w0_m * sqrt((1.0 - ((h * (t_1 * t_1)) / l)));
	} else if (t_0 <= 4e+144) {
		tmp = w0_m * sqrt((1.0 - ((t_0 * (D_m * ((M_m * 0.5) / d_m))) * (h / l))));
	} else {
		tmp = pow((sqrt(w0_m) * pow(exp(0.25), (log((-0.25 * ((h * pow((M_m * D_m), 2.0)) / l))) + (-2.0 * log(d_m))))), 2.0);
	}
	return w0_s * tmp;
}
M_m = abs(m)
D_m = abs(d)
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_m 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_m_1)
    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_m_1
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = (m_m * d_m) / (2.0d0 * d_m_1)
    t_1 = m_m * ((d_m * 0.5d0) / d_m_1)
    if (t_0 <= 1d-54) then
        tmp = w0_m * sqrt((1.0d0 - ((h * (t_1 * t_1)) / l)))
    else if (t_0 <= 4d+144) then
        tmp = w0_m * sqrt((1.0d0 - ((t_0 * (d_m * ((m_m * 0.5d0) / d_m_1))) * (h / l))))
    else
        tmp = (sqrt(w0_m) * (exp(0.25d0) ** (log(((-0.25d0) * ((h * ((m_m * d_m) ** 2.0d0)) / l))) + ((-2.0d0) * log(d_m_1))))) ** 2.0d0
    end if
    code = w0_s * tmp
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
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_m;
public static double code(double w0_s, double w0_m, double M_m, double D_m, double h, double l, double d_m) {
	double t_0 = (M_m * D_m) / (2.0 * d_m);
	double t_1 = M_m * ((D_m * 0.5) / d_m);
	double tmp;
	if (t_0 <= 1e-54) {
		tmp = w0_m * Math.sqrt((1.0 - ((h * (t_1 * t_1)) / l)));
	} else if (t_0 <= 4e+144) {
		tmp = w0_m * Math.sqrt((1.0 - ((t_0 * (D_m * ((M_m * 0.5) / d_m))) * (h / l))));
	} else {
		tmp = Math.pow((Math.sqrt(w0_m) * Math.pow(Math.exp(0.25), (Math.log((-0.25 * ((h * Math.pow((M_m * D_m), 2.0)) / l))) + (-2.0 * Math.log(d_m))))), 2.0);
	}
	return w0_s * tmp;
}
M_m = math.fabs(M)
D_m = math.fabs(D)
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_m] = sort([w0_m, M_m, D_m, h, l, d_m])
def code(w0_s, w0_m, M_m, D_m, h, l, d_m):
	t_0 = (M_m * D_m) / (2.0 * d_m)
	t_1 = M_m * ((D_m * 0.5) / d_m)
	tmp = 0
	if t_0 <= 1e-54:
		tmp = w0_m * math.sqrt((1.0 - ((h * (t_1 * t_1)) / l)))
	elif t_0 <= 4e+144:
		tmp = w0_m * math.sqrt((1.0 - ((t_0 * (D_m * ((M_m * 0.5) / d_m))) * (h / l))))
	else:
		tmp = math.pow((math.sqrt(w0_m) * math.pow(math.exp(0.25), (math.log((-0.25 * ((h * math.pow((M_m * D_m), 2.0)) / l))) + (-2.0 * math.log(d_m))))), 2.0)
	return w0_s * tmp
M_m = abs(M)
D_m = abs(D)
d_m = abs(d)
w0\_m = abs(w0)
w0\_s = copysign(1.0, w0)
w0_m, M_m, D_m, h, l, d_m = sort([w0_m, M_m, D_m, h, l, d_m])
function code(w0_s, w0_m, M_m, D_m, h, l, d_m)
	t_0 = Float64(Float64(M_m * D_m) / Float64(2.0 * d_m))
	t_1 = Float64(M_m * Float64(Float64(D_m * 0.5) / d_m))
	tmp = 0.0
	if (t_0 <= 1e-54)
		tmp = Float64(w0_m * sqrt(Float64(1.0 - Float64(Float64(h * Float64(t_1 * t_1)) / l))));
	elseif (t_0 <= 4e+144)
		tmp = Float64(w0_m * sqrt(Float64(1.0 - Float64(Float64(t_0 * Float64(D_m * Float64(Float64(M_m * 0.5) / d_m))) * Float64(h / l)))));
	else
		tmp = Float64(sqrt(w0_m) * (exp(0.25) ^ Float64(log(Float64(-0.25 * Float64(Float64(h * (Float64(M_m * D_m) ^ 2.0)) / l))) + Float64(-2.0 * log(d_m))))) ^ 2.0;
	end
	return Float64(w0_s * tmp)
end
M_m = abs(M);
D_m = abs(D);
d_m = abs(d);
w0\_m = abs(w0);
w0\_s = sign(w0) * abs(1.0);
w0_m, M_m, D_m, h, l, d_m = num2cell(sort([w0_m, M_m, D_m, h, l, d_m])){:}
function tmp_2 = code(w0_s, w0_m, M_m, D_m, h, l, d_m)
	t_0 = (M_m * D_m) / (2.0 * d_m);
	t_1 = M_m * ((D_m * 0.5) / d_m);
	tmp = 0.0;
	if (t_0 <= 1e-54)
		tmp = w0_m * sqrt((1.0 - ((h * (t_1 * t_1)) / l)));
	elseif (t_0 <= 4e+144)
		tmp = w0_m * sqrt((1.0 - ((t_0 * (D_m * ((M_m * 0.5) / d_m))) * (h / l))));
	else
		tmp = (sqrt(w0_m) * (exp(0.25) ^ (log((-0.25 * ((h * ((M_m * D_m) ^ 2.0)) / l))) + (-2.0 * log(d_m))))) ^ 2.0;
	end
	tmp_2 = w0_s * tmp;
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $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_m 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$95$m_] := Block[{t$95$0 = N[(N[(M$95$m * D$95$m), $MachinePrecision] / N[(2.0 * d$95$m), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(M$95$m * N[(N[(D$95$m * 0.5), $MachinePrecision] / d$95$m), $MachinePrecision]), $MachinePrecision]}, N[(w0$95$s * If[LessEqual[t$95$0, 1e-54], N[(w0$95$m * N[Sqrt[N[(1.0 - N[(N[(h * N[(t$95$1 * t$95$1), $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 4e+144], N[(w0$95$m * N[Sqrt[N[(1.0 - N[(N[(t$95$0 * N[(D$95$m * N[(N[(M$95$m * 0.5), $MachinePrecision] / d$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Power[N[(N[Sqrt[w0$95$m], $MachinePrecision] * N[Power[N[Exp[0.25], $MachinePrecision], N[(N[Log[N[(-0.25 * N[(N[(h * N[Power[N[(M$95$m * D$95$m), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + N[(-2.0 * N[Log[d$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]]]), $MachinePrecision]]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\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_m] = \mathsf{sort}([w0_m, M_m, D_m, h, l, d_m])\\
\\
\begin{array}{l}
t_0 := \frac{M\_m \cdot D\_m}{2 \cdot d\_m}\\
t_1 := M\_m \cdot \frac{D\_m \cdot 0.5}{d\_m}\\
w0\_s \cdot \begin{array}{l}
\mathbf{if}\;t\_0 \leq 10^{-54}:\\
\;\;\;\;w0\_m \cdot \sqrt{1 - \frac{h \cdot \left(t\_1 \cdot t\_1\right)}{\ell}}\\

\mathbf{elif}\;t\_0 \leq 4 \cdot 10^{+144}:\\
\;\;\;\;w0\_m \cdot \sqrt{1 - \left(t\_0 \cdot \left(D\_m \cdot \frac{M\_m \cdot 0.5}{d\_m}\right)\right) \cdot \frac{h}{\ell}}\\

\mathbf{else}:\\
\;\;\;\;{\left(\sqrt{w0\_m} \cdot {\left(e^{0.25}\right)}^{\left(\log \left(-0.25 \cdot \frac{h \cdot {\left(M\_m \cdot D\_m\right)}^{2}}{\ell}\right) + -2 \cdot \log d\_m\right)}\right)}^{2}\\


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

    1. Initial program 84.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1e-54 < (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) < 4.00000000000000009e144

    1. Initial program 99.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\frac{\left(D \cdot \left(M \cdot 0.5\right)\right) \cdot \left(D \cdot M\right)}{d \cdot \left(2 \cdot d\right)}} \cdot \frac{h}{\ell}} \]
    6. Step-by-step derivation
      1. times-frac99.8%

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

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

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

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

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

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

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

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

    if 4.00000000000000009e144 < (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d))

    1. Initial program 49.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto w0 \cdot \sqrt{1 - \frac{h \cdot \color{blue}{\left(\left(M \cdot \frac{D \cdot 0.5}{d}\right) \cdot \left(M \cdot \frac{D \cdot 0.5}{d}\right)\right)}}{\ell}} \]
    8. Step-by-step derivation
      1. add-sqr-sqrt33.7%

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

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

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

      \[\leadsto {\color{blue}{\left(\sqrt{w0} \cdot e^{0.25 \cdot \left(\log \left(-0.25 \cdot \frac{{D}^{2} \cdot \left({M}^{2} \cdot h\right)}{\ell}\right) + -2 \cdot \log d\right)}\right)}}^{2} \]
    11. Step-by-step derivation
      1. exp-prod22.0%

        \[\leadsto {\left(\sqrt{w0} \cdot \color{blue}{{\left(e^{0.25}\right)}^{\left(\log \left(-0.25 \cdot \frac{{D}^{2} \cdot \left({M}^{2} \cdot h\right)}{\ell}\right) + -2 \cdot \log d\right)}}\right)}^{2} \]
      2. distribute-lft-neg-in22.0%

        \[\leadsto {\left(\sqrt{w0} \cdot {\left(e^{0.25}\right)}^{\left(\log \color{blue}{\left(\left(-0.25\right) \cdot \frac{{D}^{2} \cdot \left({M}^{2} \cdot h\right)}{\ell}\right)} + -2 \cdot \log d\right)}\right)}^{2} \]
      3. metadata-eval22.0%

        \[\leadsto {\left(\sqrt{w0} \cdot {\left(e^{0.25}\right)}^{\left(\log \left(\color{blue}{-0.25} \cdot \frac{{D}^{2} \cdot \left({M}^{2} \cdot h\right)}{\ell}\right) + -2 \cdot \log d\right)}\right)}^{2} \]
      4. associate-*r*22.0%

        \[\leadsto {\left(\sqrt{w0} \cdot {\left(e^{0.25}\right)}^{\left(\log \left(-0.25 \cdot \frac{\color{blue}{\left({D}^{2} \cdot {M}^{2}\right) \cdot h}}{\ell}\right) + -2 \cdot \log d\right)}\right)}^{2} \]
      5. *-commutative22.0%

        \[\leadsto {\left(\sqrt{w0} \cdot {\left(e^{0.25}\right)}^{\left(\log \left(-0.25 \cdot \frac{\color{blue}{\left({M}^{2} \cdot {D}^{2}\right)} \cdot h}{\ell}\right) + -2 \cdot \log d\right)}\right)}^{2} \]
      6. unpow222.0%

        \[\leadsto {\left(\sqrt{w0} \cdot {\left(e^{0.25}\right)}^{\left(\log \left(-0.25 \cdot \frac{\left(\color{blue}{\left(M \cdot M\right)} \cdot {D}^{2}\right) \cdot h}{\ell}\right) + -2 \cdot \log d\right)}\right)}^{2} \]
      7. unpow222.0%

        \[\leadsto {\left(\sqrt{w0} \cdot {\left(e^{0.25}\right)}^{\left(\log \left(-0.25 \cdot \frac{\left(\left(M \cdot M\right) \cdot \color{blue}{\left(D \cdot D\right)}\right) \cdot h}{\ell}\right) + -2 \cdot \log d\right)}\right)}^{2} \]
      8. swap-sqr25.1%

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

        \[\leadsto {\left(\sqrt{w0} \cdot {\left(e^{0.25}\right)}^{\left(\log \left(-0.25 \cdot \frac{\color{blue}{{\left(M \cdot D\right)}^{2}} \cdot h}{\ell}\right) + -2 \cdot \log d\right)}\right)}^{2} \]
      10. *-commutative25.1%

        \[\leadsto {\left(\sqrt{w0} \cdot {\left(e^{0.25}\right)}^{\left(\log \left(-0.25 \cdot \frac{\color{blue}{h \cdot {\left(M \cdot D\right)}^{2}}}{\ell}\right) + -2 \cdot \log d\right)}\right)}^{2} \]
      11. *-commutative25.1%

        \[\leadsto {\left(\sqrt{w0} \cdot {\left(e^{0.25}\right)}^{\left(\log \left(-0.25 \cdot \frac{h \cdot {\color{blue}{\left(D \cdot M\right)}}^{2}}{\ell}\right) + -2 \cdot \log d\right)}\right)}^{2} \]
    12. Simplified25.1%

      \[\leadsto {\color{blue}{\left(\sqrt{w0} \cdot {\left(e^{0.25}\right)}^{\left(\log \left(-0.25 \cdot \frac{h \cdot {\left(D \cdot M\right)}^{2}}{\ell}\right) + -2 \cdot \log d\right)}\right)}}^{2} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification83.3%

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

Alternative 2: 86.8% accurate, 0.9× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\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_m] = \mathsf{sort}([w0_m, M_m, D_m, h, l, d_m])\\ \\ \begin{array}{l} t_0 := \frac{M\_m \cdot D\_m}{2 \cdot d\_m}\\ t_1 := M\_m \cdot \frac{D\_m \cdot 0.5}{d\_m}\\ w0\_s \cdot \begin{array}{l} \mathbf{if}\;1 - \frac{h}{\ell} \cdot {t\_0}^{2} \leq 4 \cdot 10^{+303}:\\ \;\;\;\;w0\_m \cdot \sqrt{1 - \left(t\_0 \cdot \left(D\_m \cdot \frac{M\_m \cdot 0.5}{d\_m}\right)\right) \cdot \frac{h}{\ell}}\\ \mathbf{else}:\\ \;\;\;\;w0\_m \cdot \sqrt{1 - \frac{h \cdot \left(t\_1 \cdot t\_1\right)}{\ell}}\\ \end{array} \end{array} \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
d_m = (fabs.f64 d)
w0\_m = (fabs.f64 w0)
w0\_s = (copysign.f64 #s(literal 1 binary64) w0)
NOTE: w0_m, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
(FPCore (w0_s w0_m M_m D_m h l d_m)
 :precision binary64
 (let* ((t_0 (/ (* M_m D_m) (* 2.0 d_m))) (t_1 (* M_m (/ (* D_m 0.5) d_m))))
   (*
    w0_s
    (if (<= (- 1.0 (* (/ h l) (pow t_0 2.0))) 4e+303)
      (* w0_m (sqrt (- 1.0 (* (* t_0 (* D_m (/ (* M_m 0.5) d_m))) (/ h l)))))
      (* w0_m (sqrt (- 1.0 (/ (* h (* t_1 t_1)) l))))))))
M_m = fabs(M);
D_m = fabs(D);
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_m);
double code(double w0_s, double w0_m, double M_m, double D_m, double h, double l, double d_m) {
	double t_0 = (M_m * D_m) / (2.0 * d_m);
	double t_1 = M_m * ((D_m * 0.5) / d_m);
	double tmp;
	if ((1.0 - ((h / l) * pow(t_0, 2.0))) <= 4e+303) {
		tmp = w0_m * sqrt((1.0 - ((t_0 * (D_m * ((M_m * 0.5) / d_m))) * (h / l))));
	} else {
		tmp = w0_m * sqrt((1.0 - ((h * (t_1 * t_1)) / l)));
	}
	return w0_s * tmp;
}
M_m = abs(m)
D_m = abs(d)
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_m 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_m_1)
    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_m_1
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = (m_m * d_m) / (2.0d0 * d_m_1)
    t_1 = m_m * ((d_m * 0.5d0) / d_m_1)
    if ((1.0d0 - ((h / l) * (t_0 ** 2.0d0))) <= 4d+303) then
        tmp = w0_m * sqrt((1.0d0 - ((t_0 * (d_m * ((m_m * 0.5d0) / d_m_1))) * (h / l))))
    else
        tmp = w0_m * sqrt((1.0d0 - ((h * (t_1 * t_1)) / l)))
    end if
    code = w0_s * tmp
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
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_m;
public static double code(double w0_s, double w0_m, double M_m, double D_m, double h, double l, double d_m) {
	double t_0 = (M_m * D_m) / (2.0 * d_m);
	double t_1 = M_m * ((D_m * 0.5) / d_m);
	double tmp;
	if ((1.0 - ((h / l) * Math.pow(t_0, 2.0))) <= 4e+303) {
		tmp = w0_m * Math.sqrt((1.0 - ((t_0 * (D_m * ((M_m * 0.5) / d_m))) * (h / l))));
	} else {
		tmp = w0_m * Math.sqrt((1.0 - ((h * (t_1 * t_1)) / l)));
	}
	return w0_s * tmp;
}
M_m = math.fabs(M)
D_m = math.fabs(D)
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_m] = sort([w0_m, M_m, D_m, h, l, d_m])
def code(w0_s, w0_m, M_m, D_m, h, l, d_m):
	t_0 = (M_m * D_m) / (2.0 * d_m)
	t_1 = M_m * ((D_m * 0.5) / d_m)
	tmp = 0
	if (1.0 - ((h / l) * math.pow(t_0, 2.0))) <= 4e+303:
		tmp = w0_m * math.sqrt((1.0 - ((t_0 * (D_m * ((M_m * 0.5) / d_m))) * (h / l))))
	else:
		tmp = w0_m * math.sqrt((1.0 - ((h * (t_1 * t_1)) / l)))
	return w0_s * tmp
M_m = abs(M)
D_m = abs(D)
d_m = abs(d)
w0\_m = abs(w0)
w0\_s = copysign(1.0, w0)
w0_m, M_m, D_m, h, l, d_m = sort([w0_m, M_m, D_m, h, l, d_m])
function code(w0_s, w0_m, M_m, D_m, h, l, d_m)
	t_0 = Float64(Float64(M_m * D_m) / Float64(2.0 * d_m))
	t_1 = Float64(M_m * Float64(Float64(D_m * 0.5) / d_m))
	tmp = 0.0
	if (Float64(1.0 - Float64(Float64(h / l) * (t_0 ^ 2.0))) <= 4e+303)
		tmp = Float64(w0_m * sqrt(Float64(1.0 - Float64(Float64(t_0 * Float64(D_m * Float64(Float64(M_m * 0.5) / d_m))) * Float64(h / l)))));
	else
		tmp = Float64(w0_m * sqrt(Float64(1.0 - Float64(Float64(h * Float64(t_1 * t_1)) / l))));
	end
	return Float64(w0_s * tmp)
end
M_m = abs(M);
D_m = abs(D);
d_m = abs(d);
w0\_m = abs(w0);
w0\_s = sign(w0) * abs(1.0);
w0_m, M_m, D_m, h, l, d_m = num2cell(sort([w0_m, M_m, D_m, h, l, d_m])){:}
function tmp_2 = code(w0_s, w0_m, M_m, D_m, h, l, d_m)
	t_0 = (M_m * D_m) / (2.0 * d_m);
	t_1 = M_m * ((D_m * 0.5) / d_m);
	tmp = 0.0;
	if ((1.0 - ((h / l) * (t_0 ^ 2.0))) <= 4e+303)
		tmp = w0_m * sqrt((1.0 - ((t_0 * (D_m * ((M_m * 0.5) / d_m))) * (h / l))));
	else
		tmp = w0_m * sqrt((1.0 - ((h * (t_1 * t_1)) / l)));
	end
	tmp_2 = w0_s * tmp;
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $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_m 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$95$m_] := Block[{t$95$0 = N[(N[(M$95$m * D$95$m), $MachinePrecision] / N[(2.0 * d$95$m), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(M$95$m * N[(N[(D$95$m * 0.5), $MachinePrecision] / d$95$m), $MachinePrecision]), $MachinePrecision]}, N[(w0$95$s * If[LessEqual[N[(1.0 - N[(N[(h / l), $MachinePrecision] * N[Power[t$95$0, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 4e+303], N[(w0$95$m * N[Sqrt[N[(1.0 - N[(N[(t$95$0 * N[(D$95$m * N[(N[(M$95$m * 0.5), $MachinePrecision] / d$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(w0$95$m * N[Sqrt[N[(1.0 - N[(N[(h * N[(t$95$1 * t$95$1), $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\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_m] = \mathsf{sort}([w0_m, M_m, D_m, h, l, d_m])\\
\\
\begin{array}{l}
t_0 := \frac{M\_m \cdot D\_m}{2 \cdot d\_m}\\
t_1 := M\_m \cdot \frac{D\_m \cdot 0.5}{d\_m}\\
w0\_s \cdot \begin{array}{l}
\mathbf{if}\;1 - \frac{h}{\ell} \cdot {t\_0}^{2} \leq 4 \cdot 10^{+303}:\\
\;\;\;\;w0\_m \cdot \sqrt{1 - \left(t\_0 \cdot \left(D\_m \cdot \frac{M\_m \cdot 0.5}{d\_m}\right)\right) \cdot \frac{h}{\ell}}\\

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


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

    1. Initial program 99.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\frac{\left(D \cdot \left(M \cdot 0.5\right)\right) \cdot \left(D \cdot M\right)}{d \cdot \left(2 \cdot d\right)}} \cdot \frac{h}{\ell}} \]
    6. Step-by-step derivation
      1. times-frac99.9%

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

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

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

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

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

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

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

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

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

    1. Initial program 41.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 82.6% accurate, 1.7× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\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_m] = \mathsf{sort}([w0_m, M_m, D_m, h, l, d_m])\\ \\ w0\_s \cdot \begin{array}{l} \mathbf{if}\;M\_m \cdot D\_m \leq 5 \cdot 10^{-128}:\\ \;\;\;\;w0\_m\\ \mathbf{else}:\\ \;\;\;\;w0\_m \cdot \sqrt{1 - \left(M\_m \cdot D\_m\right) \cdot \left(\frac{h}{\ell} \cdot \left(\frac{M\_m \cdot \left(D\_m \cdot 0.5\right)}{d\_m} \cdot \frac{0.5}{d\_m}\right)\right)}\\ \end{array} \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
d_m = (fabs.f64 d)
w0\_m = (fabs.f64 w0)
w0\_s = (copysign.f64 #s(literal 1 binary64) w0)
NOTE: w0_m, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
(FPCore (w0_s w0_m M_m D_m h l d_m)
 :precision binary64
 (*
  w0_s
  (if (<= (* M_m D_m) 5e-128)
    w0_m
    (*
     w0_m
     (sqrt
      (-
       1.0
       (*
        (* M_m D_m)
        (* (/ h l) (* (/ (* M_m (* D_m 0.5)) d_m) (/ 0.5 d_m))))))))))
M_m = fabs(M);
D_m = fabs(D);
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_m);
double code(double w0_s, double w0_m, double M_m, double D_m, double h, double l, double d_m) {
	double tmp;
	if ((M_m * D_m) <= 5e-128) {
		tmp = w0_m;
	} else {
		tmp = w0_m * sqrt((1.0 - ((M_m * D_m) * ((h / l) * (((M_m * (D_m * 0.5)) / d_m) * (0.5 / d_m))))));
	}
	return w0_s * tmp;
}
M_m = abs(m)
D_m = abs(d)
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_m 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_m_1)
    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_m_1
    real(8) :: tmp
    if ((m_m * d_m) <= 5d-128) then
        tmp = w0_m
    else
        tmp = w0_m * sqrt((1.0d0 - ((m_m * d_m) * ((h / l) * (((m_m * (d_m * 0.5d0)) / d_m_1) * (0.5d0 / d_m_1))))))
    end if
    code = w0_s * tmp
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
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_m;
public static double code(double w0_s, double w0_m, double M_m, double D_m, double h, double l, double d_m) {
	double tmp;
	if ((M_m * D_m) <= 5e-128) {
		tmp = w0_m;
	} else {
		tmp = w0_m * Math.sqrt((1.0 - ((M_m * D_m) * ((h / l) * (((M_m * (D_m * 0.5)) / d_m) * (0.5 / d_m))))));
	}
	return w0_s * tmp;
}
M_m = math.fabs(M)
D_m = math.fabs(D)
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_m] = sort([w0_m, M_m, D_m, h, l, d_m])
def code(w0_s, w0_m, M_m, D_m, h, l, d_m):
	tmp = 0
	if (M_m * D_m) <= 5e-128:
		tmp = w0_m
	else:
		tmp = w0_m * math.sqrt((1.0 - ((M_m * D_m) * ((h / l) * (((M_m * (D_m * 0.5)) / d_m) * (0.5 / d_m))))))
	return w0_s * tmp
M_m = abs(M)
D_m = abs(D)
d_m = abs(d)
w0\_m = abs(w0)
w0\_s = copysign(1.0, w0)
w0_m, M_m, D_m, h, l, d_m = sort([w0_m, M_m, D_m, h, l, d_m])
function code(w0_s, w0_m, M_m, D_m, h, l, d_m)
	tmp = 0.0
	if (Float64(M_m * D_m) <= 5e-128)
		tmp = w0_m;
	else
		tmp = Float64(w0_m * sqrt(Float64(1.0 - Float64(Float64(M_m * D_m) * Float64(Float64(h / l) * Float64(Float64(Float64(M_m * Float64(D_m * 0.5)) / d_m) * Float64(0.5 / d_m)))))));
	end
	return Float64(w0_s * tmp)
end
M_m = abs(M);
D_m = abs(D);
d_m = abs(d);
w0\_m = abs(w0);
w0\_s = sign(w0) * abs(1.0);
w0_m, M_m, D_m, h, l, d_m = num2cell(sort([w0_m, M_m, D_m, h, l, d_m])){:}
function tmp_2 = code(w0_s, w0_m, M_m, D_m, h, l, d_m)
	tmp = 0.0;
	if ((M_m * D_m) <= 5e-128)
		tmp = w0_m;
	else
		tmp = w0_m * sqrt((1.0 - ((M_m * D_m) * ((h / l) * (((M_m * (D_m * 0.5)) / d_m) * (0.5 / d_m))))));
	end
	tmp_2 = w0_s * tmp;
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $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_m 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$95$m_] := N[(w0$95$s * If[LessEqual[N[(M$95$m * D$95$m), $MachinePrecision], 5e-128], w0$95$m, N[(w0$95$m * N[Sqrt[N[(1.0 - N[(N[(M$95$m * D$95$m), $MachinePrecision] * N[(N[(h / l), $MachinePrecision] * N[(N[(N[(M$95$m * N[(D$95$m * 0.5), $MachinePrecision]), $MachinePrecision] / d$95$m), $MachinePrecision] * N[(0.5 / d$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\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_m] = \mathsf{sort}([w0_m, M_m, D_m, h, l, d_m])\\
\\
w0\_s \cdot \begin{array}{l}
\mathbf{if}\;M\_m \cdot D\_m \leq 5 \cdot 10^{-128}:\\
\;\;\;\;w0\_m\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 M D) < 5.0000000000000001e-128

    1. Initial program 84.4%

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

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

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

    if 5.0000000000000001e-128 < (*.f64 M D)

    1. Initial program 76.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 70.8% accurate, 1.7× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\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_m] = \mathsf{sort}([w0_m, M_m, D_m, h, l, d_m])\\ \\ w0\_s \cdot \begin{array}{l} \mathbf{if}\;M\_m \cdot D\_m \leq 3.6 \cdot 10^{-125}:\\ \;\;\;\;w0\_m\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-0.125, \frac{\left(\left(M\_m \cdot D\_m\right) \cdot \left(M\_m \cdot D\_m\right)\right) \cdot \left(w0\_m \cdot h\right)}{\ell \cdot \left(d\_m \cdot d\_m\right)}, w0\_m\right)\\ \end{array} \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
d_m = (fabs.f64 d)
w0\_m = (fabs.f64 w0)
w0\_s = (copysign.f64 #s(literal 1 binary64) w0)
NOTE: w0_m, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
(FPCore (w0_s w0_m M_m D_m h l d_m)
 :precision binary64
 (*
  w0_s
  (if (<= (* M_m D_m) 3.6e-125)
    w0_m
    (fma
     -0.125
     (/ (* (* (* M_m D_m) (* M_m D_m)) (* w0_m h)) (* l (* d_m d_m)))
     w0_m))))
M_m = fabs(M);
D_m = fabs(D);
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_m);
double code(double w0_s, double w0_m, double M_m, double D_m, double h, double l, double d_m) {
	double tmp;
	if ((M_m * D_m) <= 3.6e-125) {
		tmp = w0_m;
	} else {
		tmp = fma(-0.125, ((((M_m * D_m) * (M_m * D_m)) * (w0_m * h)) / (l * (d_m * d_m))), w0_m);
	}
	return w0_s * tmp;
}
M_m = abs(M)
D_m = abs(D)
d_m = abs(d)
w0\_m = abs(w0)
w0\_s = copysign(1.0, w0)
w0_m, M_m, D_m, h, l, d_m = sort([w0_m, M_m, D_m, h, l, d_m])
function code(w0_s, w0_m, M_m, D_m, h, l, d_m)
	tmp = 0.0
	if (Float64(M_m * D_m) <= 3.6e-125)
		tmp = w0_m;
	else
		tmp = fma(-0.125, Float64(Float64(Float64(Float64(M_m * D_m) * Float64(M_m * D_m)) * Float64(w0_m * h)) / Float64(l * Float64(d_m * d_m))), w0_m);
	end
	return Float64(w0_s * tmp)
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $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_m 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$95$m_] := N[(w0$95$s * If[LessEqual[N[(M$95$m * D$95$m), $MachinePrecision], 3.6e-125], w0$95$m, N[(-0.125 * N[(N[(N[(N[(M$95$m * D$95$m), $MachinePrecision] * N[(M$95$m * D$95$m), $MachinePrecision]), $MachinePrecision] * N[(w0$95$m * h), $MachinePrecision]), $MachinePrecision] / N[(l * N[(d$95$m * d$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + w0$95$m), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\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_m] = \mathsf{sort}([w0_m, M_m, D_m, h, l, d_m])\\
\\
w0\_s \cdot \begin{array}{l}
\mathbf{if}\;M\_m \cdot D\_m \leq 3.6 \cdot 10^{-125}:\\
\;\;\;\;w0\_m\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 M D) < 3.6000000000000002e-125

    1. Initial program 84.4%

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

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

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

    if 3.6000000000000002e-125 < (*.f64 M D)

    1. Initial program 76.2%

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

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

      \[\leadsto \color{blue}{w0 + -0.125 \cdot \frac{{D}^{2} \cdot \left({M}^{2} \cdot \left(h \cdot w0\right)\right)}{{d}^{2} \cdot \ell}} \]
    5. Step-by-step derivation
      1. +-commutative50.2%

        \[\leadsto \color{blue}{-0.125 \cdot \frac{{D}^{2} \cdot \left({M}^{2} \cdot \left(h \cdot w0\right)\right)}{{d}^{2} \cdot \ell} + w0} \]
      2. fma-define50.2%

        \[\leadsto \color{blue}{\mathsf{fma}\left(-0.125, \frac{{D}^{2} \cdot \left({M}^{2} \cdot \left(h \cdot w0\right)\right)}{{d}^{2} \cdot \ell}, w0\right)} \]
      3. associate-*r*50.2%

        \[\leadsto \mathsf{fma}\left(-0.125, \frac{\color{blue}{\left({D}^{2} \cdot {M}^{2}\right) \cdot \left(h \cdot w0\right)}}{{d}^{2} \cdot \ell}, w0\right) \]
      4. unpow250.2%

        \[\leadsto \mathsf{fma}\left(-0.125, \frac{\left(\color{blue}{\left(D \cdot D\right)} \cdot {M}^{2}\right) \cdot \left(h \cdot w0\right)}{{d}^{2} \cdot \ell}, w0\right) \]
      5. unpow250.2%

        \[\leadsto \mathsf{fma}\left(-0.125, \frac{\left(\left(D \cdot D\right) \cdot \color{blue}{\left(M \cdot M\right)}\right) \cdot \left(h \cdot w0\right)}{{d}^{2} \cdot \ell}, w0\right) \]
      6. swap-sqr61.4%

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(-0.125, \frac{{\left(D \cdot M\right)}^{2} \cdot \left(h \cdot w0\right)}{{d}^{2} \cdot \ell}, w0\right)} \]
    7. Step-by-step derivation
      1. unpow261.4%

        \[\leadsto \mathsf{fma}\left(-0.125, \frac{\color{blue}{\left(\left(D \cdot M\right) \cdot \left(D \cdot M\right)\right)} \cdot \left(h \cdot w0\right)}{{d}^{2} \cdot \ell}, w0\right) \]
      2. *-commutative61.4%

        \[\leadsto \mathsf{fma}\left(-0.125, \frac{\left(\color{blue}{\left(M \cdot D\right)} \cdot \left(D \cdot M\right)\right) \cdot \left(h \cdot w0\right)}{{d}^{2} \cdot \ell}, w0\right) \]
      3. *-commutative61.4%

        \[\leadsto \mathsf{fma}\left(-0.125, \frac{\left(\left(M \cdot D\right) \cdot \color{blue}{\left(M \cdot D\right)}\right) \cdot \left(h \cdot w0\right)}{{d}^{2} \cdot \ell}, w0\right) \]
    8. Applied egg-rr61.4%

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

        \[\leadsto \mathsf{fma}\left(-0.125, \frac{\left(\left(M \cdot D\right) \cdot \left(M \cdot D\right)\right) \cdot \left(h \cdot w0\right)}{\color{blue}{\left(d \cdot d\right)} \cdot \ell}, w0\right) \]
    10. Applied egg-rr61.4%

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

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

Alternative 5: 67.9% accurate, 216.0× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\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_m] = \mathsf{sort}([w0_m, M_m, D_m, h, l, d_m])\\ \\ w0\_s \cdot w0\_m \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
d_m = (fabs.f64 d)
w0\_m = (fabs.f64 w0)
w0\_s = (copysign.f64 #s(literal 1 binary64) w0)
NOTE: w0_m, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
(FPCore (w0_s w0_m M_m D_m h l d_m) :precision binary64 (* w0_s w0_m))
M_m = fabs(M);
D_m = fabs(D);
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_m);
double code(double w0_s, double w0_m, double M_m, double D_m, double h, double l, double d_m) {
	return w0_s * w0_m;
}
M_m = abs(m)
D_m = abs(d)
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_m 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_m_1)
    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_m_1
    code = w0_s * w0_m
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
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_m;
public static double code(double w0_s, double w0_m, double M_m, double D_m, double h, double l, double d_m) {
	return w0_s * w0_m;
}
M_m = math.fabs(M)
D_m = math.fabs(D)
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_m] = sort([w0_m, M_m, D_m, h, l, d_m])
def code(w0_s, w0_m, M_m, D_m, h, l, d_m):
	return w0_s * w0_m
M_m = abs(M)
D_m = abs(D)
d_m = abs(d)
w0\_m = abs(w0)
w0\_s = copysign(1.0, w0)
w0_m, M_m, D_m, h, l, d_m = sort([w0_m, M_m, D_m, h, l, d_m])
function code(w0_s, w0_m, M_m, D_m, h, l, d_m)
	return Float64(w0_s * w0_m)
end
M_m = abs(M);
D_m = abs(D);
d_m = abs(d);
w0\_m = abs(w0);
w0\_s = sign(w0) * abs(1.0);
w0_m, M_m, D_m, h, l, d_m = num2cell(sort([w0_m, M_m, D_m, h, l, d_m])){:}
function tmp = code(w0_s, w0_m, M_m, D_m, h, l, d_m)
	tmp = w0_s * w0_m;
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $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_m 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$95$m_] := N[(w0$95$s * w0$95$m), $MachinePrecision]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\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_m] = \mathsf{sort}([w0_m, M_m, D_m, h, l, d_m])\\
\\
w0\_s \cdot w0\_m
\end{array}
Derivation
  1. Initial program 82.2%

    \[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(D \cdot \frac{\frac{M}{2}}{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 2024129 
(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))))))