Henrywood and Agarwal, Equation (9a)

Percentage Accurate: 81.5% → 88.1%
Time: 13.3s
Alternatives: 12
Speedup: 0.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 12 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 81.5% accurate, 1.0× speedup?

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

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

Alternative 1: 88.1% accurate, 0.7× speedup?

\[\begin{array}{l} M = |M|\\ D = |D|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ \begin{array}{l} \mathbf{if}\;{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \leq 10^{+61}:\\ \;\;\;\;w0 \cdot \sqrt{1 + \left(h \cdot {\left(M \cdot \frac{\frac{D}{2}}{d}\right)}^{2}\right) \cdot \frac{-1}{\ell}}\\ \mathbf{else}:\\ \;\;\;\;w0 \cdot \sqrt{1 + \frac{D \cdot h}{\frac{\ell}{D} \cdot \left(\frac{d}{M} \cdot \frac{d}{M}\right)} \cdot -0.25}\\ \end{array} \end{array} \]
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
(FPCore (w0 M D h l d)
 :precision binary64
 (if (<= (pow (/ (* M D) (* 2.0 d)) 2.0) 1e+61)
   (* w0 (sqrt (+ 1.0 (* (* h (pow (* M (/ (/ D 2.0) d)) 2.0)) (/ -1.0 l)))))
   (*
    w0
    (sqrt (+ 1.0 (* (/ (* D h) (* (/ l D) (* (/ d M) (/ d M)))) -0.25))))))
M = abs(M);
D = abs(D);
assert(M < D);
double code(double w0, double M, double D, double h, double l, double d) {
	double tmp;
	if (pow(((M * D) / (2.0 * d)), 2.0) <= 1e+61) {
		tmp = w0 * sqrt((1.0 + ((h * pow((M * ((D / 2.0) / d)), 2.0)) * (-1.0 / l))));
	} else {
		tmp = w0 * sqrt((1.0 + (((D * h) / ((l / D) * ((d / M) * (d / M)))) * -0.25)));
	}
	return tmp;
}
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
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
    real(8) :: tmp
    if ((((m * d) / (2.0d0 * d_1)) ** 2.0d0) <= 1d+61) then
        tmp = w0 * sqrt((1.0d0 + ((h * ((m * ((d / 2.0d0) / d_1)) ** 2.0d0)) * ((-1.0d0) / l))))
    else
        tmp = w0 * sqrt((1.0d0 + (((d * h) / ((l / d) * ((d_1 / m) * (d_1 / m)))) * (-0.25d0))))
    end if
    code = tmp
end function
M = Math.abs(M);
D = Math.abs(D);
assert M < D;
public static double code(double w0, double M, double D, double h, double l, double d) {
	double tmp;
	if (Math.pow(((M * D) / (2.0 * d)), 2.0) <= 1e+61) {
		tmp = w0 * Math.sqrt((1.0 + ((h * Math.pow((M * ((D / 2.0) / d)), 2.0)) * (-1.0 / l))));
	} else {
		tmp = w0 * Math.sqrt((1.0 + (((D * h) / ((l / D) * ((d / M) * (d / M)))) * -0.25)));
	}
	return tmp;
}
M = abs(M)
D = abs(D)
[M, D] = sort([M, D])
def code(w0, M, D, h, l, d):
	tmp = 0
	if math.pow(((M * D) / (2.0 * d)), 2.0) <= 1e+61:
		tmp = w0 * math.sqrt((1.0 + ((h * math.pow((M * ((D / 2.0) / d)), 2.0)) * (-1.0 / l))))
	else:
		tmp = w0 * math.sqrt((1.0 + (((D * h) / ((l / D) * ((d / M) * (d / M)))) * -0.25)))
	return tmp
M = abs(M)
D = abs(D)
M, D = sort([M, D])
function code(w0, M, D, h, l, d)
	tmp = 0.0
	if ((Float64(Float64(M * D) / Float64(2.0 * d)) ^ 2.0) <= 1e+61)
		tmp = Float64(w0 * sqrt(Float64(1.0 + Float64(Float64(h * (Float64(M * Float64(Float64(D / 2.0) / d)) ^ 2.0)) * Float64(-1.0 / l)))));
	else
		tmp = Float64(w0 * sqrt(Float64(1.0 + Float64(Float64(Float64(D * h) / Float64(Float64(l / D) * Float64(Float64(d / M) * Float64(d / M)))) * -0.25))));
	end
	return tmp
end
M = abs(M)
D = abs(D)
M, D = num2cell(sort([M, D])){:}
function tmp_2 = code(w0, M, D, h, l, d)
	tmp = 0.0;
	if ((((M * D) / (2.0 * d)) ^ 2.0) <= 1e+61)
		tmp = w0 * sqrt((1.0 + ((h * ((M * ((D / 2.0) / d)) ^ 2.0)) * (-1.0 / l))));
	else
		tmp = w0 * sqrt((1.0 + (((D * h) / ((l / D) * ((d / M) * (d / M)))) * -0.25)));
	end
	tmp_2 = tmp;
end
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
code[w0_, M_, D_, h_, l_, d_] := If[LessEqual[N[Power[N[(N[(M * D), $MachinePrecision] / N[(2.0 * d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision], 1e+61], N[(w0 * N[Sqrt[N[(1.0 + N[(N[(h * N[Power[N[(M * N[(N[(D / 2.0), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] * N[(-1.0 / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(w0 * N[Sqrt[N[(1.0 + N[(N[(N[(D * h), $MachinePrecision] / N[(N[(l / D), $MachinePrecision] * N[(N[(d / M), $MachinePrecision] * N[(d / M), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
M = |M|\\
D = |D|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\begin{array}{l}
\mathbf{if}\;{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \leq 10^{+61}:\\
\;\;\;\;w0 \cdot \sqrt{1 + \left(h \cdot {\left(M \cdot \frac{\frac{D}{2}}{d}\right)}^{2}\right) \cdot \frac{-1}{\ell}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (pow.f64 (/.f64 (*.f64 M D) (*.f64 2 d)) 2) < 9.99999999999999949e60

    1. Initial program 92.5%

      \[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]
    2. Step-by-step derivation
      1. *-commutative92.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 9.99999999999999949e60 < (pow.f64 (/.f64 (*.f64 M D) (*.f64 2 d)) 2)

    1. Initial program 61.6%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto w0 \cdot \sqrt{1 + \color{blue}{\left(-\frac{{D}^{2} \cdot \left(h \cdot {M}^{2}\right)}{\ell \cdot {d}^{2}} \cdot 0.25\right)}} \]
      8. distribute-rgt-neg-in36.2%

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

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

        \[\leadsto w0 \cdot \sqrt{1 + \color{blue}{\frac{D \cdot h}{\frac{\ell}{D} \cdot \frac{d \cdot d}{M \cdot M}}} \cdot -0.25} \]
      2. times-frac66.3%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \leq 10^{+61}:\\ \;\;\;\;w0 \cdot \sqrt{1 + \left(h \cdot {\left(M \cdot \frac{\frac{D}{2}}{d}\right)}^{2}\right) \cdot \frac{-1}{\ell}}\\ \mathbf{else}:\\ \;\;\;\;w0 \cdot \sqrt{1 + \frac{D \cdot h}{\frac{\ell}{D} \cdot \left(\frac{d}{M} \cdot \frac{d}{M}\right)} \cdot -0.25}\\ \end{array} \]

Alternative 2: 87.5% accurate, 0.7× speedup?

\[\begin{array}{l} M = |M|\\ D = |D|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ \begin{array}{l} \mathbf{if}\;{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell} \leq 4 \cdot 10^{-15}:\\ \;\;\;\;w0 \cdot \sqrt{1 - \frac{h}{\ell} \cdot {\left(\frac{D}{2} \cdot \frac{M}{d}\right)}^{2}}\\ \mathbf{else}:\\ \;\;\;\;w0 \cdot \left(1 + \left(D \cdot \frac{\frac{D}{\frac{\frac{d}{M} \cdot \frac{d}{M}}{h}}}{\ell}\right) \cdot -0.125\right)\\ \end{array} \end{array} \]
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
(FPCore (w0 M D h l d)
 :precision binary64
 (if (<= (* (pow (/ (* M D) (* 2.0 d)) 2.0) (/ h l)) 4e-15)
   (* w0 (sqrt (- 1.0 (* (/ h l) (pow (* (/ D 2.0) (/ M d)) 2.0)))))
   (* w0 (+ 1.0 (* (* D (/ (/ D (/ (* (/ d M) (/ d M)) h)) l)) -0.125)))))
M = abs(M);
D = abs(D);
assert(M < D);
double code(double w0, double M, double D, double h, double l, double d) {
	double tmp;
	if ((pow(((M * D) / (2.0 * d)), 2.0) * (h / l)) <= 4e-15) {
		tmp = w0 * sqrt((1.0 - ((h / l) * pow(((D / 2.0) * (M / d)), 2.0))));
	} else {
		tmp = w0 * (1.0 + ((D * ((D / (((d / M) * (d / M)) / h)) / l)) * -0.125));
	}
	return tmp;
}
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
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
    real(8) :: tmp
    if (((((m * d) / (2.0d0 * d_1)) ** 2.0d0) * (h / l)) <= 4d-15) then
        tmp = w0 * sqrt((1.0d0 - ((h / l) * (((d / 2.0d0) * (m / d_1)) ** 2.0d0))))
    else
        tmp = w0 * (1.0d0 + ((d * ((d / (((d_1 / m) * (d_1 / m)) / h)) / l)) * (-0.125d0)))
    end if
    code = tmp
end function
M = Math.abs(M);
D = Math.abs(D);
assert M < D;
public static double code(double w0, double M, double D, double h, double l, double d) {
	double tmp;
	if ((Math.pow(((M * D) / (2.0 * d)), 2.0) * (h / l)) <= 4e-15) {
		tmp = w0 * Math.sqrt((1.0 - ((h / l) * Math.pow(((D / 2.0) * (M / d)), 2.0))));
	} else {
		tmp = w0 * (1.0 + ((D * ((D / (((d / M) * (d / M)) / h)) / l)) * -0.125));
	}
	return tmp;
}
M = abs(M)
D = abs(D)
[M, D] = sort([M, D])
def code(w0, M, D, h, l, d):
	tmp = 0
	if (math.pow(((M * D) / (2.0 * d)), 2.0) * (h / l)) <= 4e-15:
		tmp = w0 * math.sqrt((1.0 - ((h / l) * math.pow(((D / 2.0) * (M / d)), 2.0))))
	else:
		tmp = w0 * (1.0 + ((D * ((D / (((d / M) * (d / M)) / h)) / l)) * -0.125))
	return tmp
M = abs(M)
D = abs(D)
M, D = sort([M, D])
function code(w0, M, D, h, l, d)
	tmp = 0.0
	if (Float64((Float64(Float64(M * D) / Float64(2.0 * d)) ^ 2.0) * Float64(h / l)) <= 4e-15)
		tmp = Float64(w0 * sqrt(Float64(1.0 - Float64(Float64(h / l) * (Float64(Float64(D / 2.0) * Float64(M / d)) ^ 2.0)))));
	else
		tmp = Float64(w0 * Float64(1.0 + Float64(Float64(D * Float64(Float64(D / Float64(Float64(Float64(d / M) * Float64(d / M)) / h)) / l)) * -0.125)));
	end
	return tmp
end
M = abs(M)
D = abs(D)
M, D = num2cell(sort([M, D])){:}
function tmp_2 = code(w0, M, D, h, l, d)
	tmp = 0.0;
	if (((((M * D) / (2.0 * d)) ^ 2.0) * (h / l)) <= 4e-15)
		tmp = w0 * sqrt((1.0 - ((h / l) * (((D / 2.0) * (M / d)) ^ 2.0))));
	else
		tmp = w0 * (1.0 + ((D * ((D / (((d / M) * (d / M)) / h)) / l)) * -0.125));
	end
	tmp_2 = tmp;
end
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
code[w0_, M_, D_, h_, l_, d_] := If[LessEqual[N[(N[Power[N[(N[(M * D), $MachinePrecision] / N[(2.0 * d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision], 4e-15], N[(w0 * N[Sqrt[N[(1.0 - N[(N[(h / l), $MachinePrecision] * N[Power[N[(N[(D / 2.0), $MachinePrecision] * N[(M / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(w0 * N[(1.0 + N[(N[(D * N[(N[(D / N[(N[(N[(d / M), $MachinePrecision] * N[(d / M), $MachinePrecision]), $MachinePrecision] / h), $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision] * -0.125), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
M = |M|\\
D = |D|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\begin{array}{l}
\mathbf{if}\;{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell} \leq 4 \cdot 10^{-15}:\\
\;\;\;\;w0 \cdot \sqrt{1 - \frac{h}{\ell} \cdot {\left(\frac{D}{2} \cdot \frac{M}{d}\right)}^{2}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 2 d)) 2) (/.f64 h l)) < 4.0000000000000003e-15

    1. Initial program 89.9%

      \[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]
    2. Step-by-step derivation
      1. *-commutative89.9%

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

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

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

    if 4.0000000000000003e-15 < (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 2 d)) 2) (/.f64 h l))

    1. Initial program 0.0%

      \[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]
    2. Step-by-step derivation
      1. *-commutative0.0%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto w0 \cdot \left(1 + \left(\frac{D \cdot D}{d \cdot d} \cdot \frac{\color{blue}{\left(M \cdot M\right)} \cdot h}{\ell}\right) \cdot -0.125\right) \]
    6. Simplified38.5%

      \[\leadsto w0 \cdot \color{blue}{\left(1 + \left(\frac{D \cdot D}{d \cdot d} \cdot \frac{\left(M \cdot M\right) \cdot h}{\ell}\right) \cdot -0.125\right)} \]
    7. Taylor expanded in D around 0 38.5%

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

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

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

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

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

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

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

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

        \[\leadsto w0 \cdot \left(1 + \color{blue}{\left(D \cdot \left(\frac{D}{\ell} \cdot \left(\frac{h}{d \cdot d} \cdot \left(M \cdot M\right)\right)\right)\right)} \cdot -0.125\right) \]
      9. *-commutative57.5%

        \[\leadsto w0 \cdot \left(1 + \left(D \cdot \color{blue}{\left(\left(\frac{h}{d \cdot d} \cdot \left(M \cdot M\right)\right) \cdot \frac{D}{\ell}\right)}\right) \cdot -0.125\right) \]
      10. associate-*r/67.1%

        \[\leadsto w0 \cdot \left(1 + \left(D \cdot \color{blue}{\frac{\left(\frac{h}{d \cdot d} \cdot \left(M \cdot M\right)\right) \cdot D}{\ell}}\right) \cdot -0.125\right) \]
      11. *-commutative67.1%

        \[\leadsto w0 \cdot \left(1 + \left(D \cdot \frac{\color{blue}{\left(\left(M \cdot M\right) \cdot \frac{h}{d \cdot d}\right)} \cdot D}{\ell}\right) \cdot -0.125\right) \]
      12. associate-*l*67.1%

        \[\leadsto w0 \cdot \left(1 + \left(D \cdot \frac{\color{blue}{\left(M \cdot M\right) \cdot \left(\frac{h}{d \cdot d} \cdot D\right)}}{\ell}\right) \cdot -0.125\right) \]
      13. *-commutative67.1%

        \[\leadsto w0 \cdot \left(1 + \left(D \cdot \frac{\left(M \cdot M\right) \cdot \color{blue}{\left(D \cdot \frac{h}{d \cdot d}\right)}}{\ell}\right) \cdot -0.125\right) \]
      14. unpow267.1%

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

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

        \[\leadsto w0 \cdot \left(1 + \left(D \cdot \frac{\left(M \cdot M\right) \cdot \frac{D \cdot h}{\color{blue}{d \cdot d}}}{\ell}\right) \cdot -0.125\right) \]
    9. Simplified57.5%

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

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

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

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

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

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

        \[\leadsto w0 \cdot \left(1 + \left(D \cdot \frac{\frac{D}{\frac{\frac{\color{blue}{d \cdot d}}{M \cdot M}}{h}}}{\ell}\right) \cdot -0.125\right) \]
      6. times-frac72.6%

        \[\leadsto w0 \cdot \left(1 + \left(D \cdot \frac{\frac{D}{\frac{\color{blue}{\frac{d}{M} \cdot \frac{d}{M}}}{h}}}{\ell}\right) \cdot -0.125\right) \]
      7. unpow272.6%

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

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

        \[\leadsto w0 \cdot \left(1 + \left(D \cdot \frac{\frac{D}{\frac{\color{blue}{\frac{d}{M} \cdot \frac{d}{M}}}{h}}}{\ell}\right) \cdot -0.125\right) \]
    14. Applied egg-rr72.6%

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

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

Alternative 3: 86.2% accurate, 0.7× speedup?

\[\begin{array}{l} M = |M|\\ D = |D|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ \begin{array}{l} t_0 := {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\\ \mathbf{if}\;t_0 \leq \infty:\\ \;\;\;\;w0 \cdot \sqrt{1 - \frac{h}{\frac{\ell}{t_0}}}\\ \mathbf{else}:\\ \;\;\;\;w0 \cdot \sqrt{1 + -0.25 \cdot \left(\left(M \cdot \left(\frac{D}{d} \cdot \frac{D}{\ell}\right)\right) \cdot \frac{h}{\frac{d}{M}}\right)}\\ \end{array} \end{array} \]
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
(FPCore (w0 M D h l d)
 :precision binary64
 (let* ((t_0 (pow (/ (* M D) (* 2.0 d)) 2.0)))
   (if (<= t_0 INFINITY)
     (* w0 (sqrt (- 1.0 (/ h (/ l t_0)))))
     (*
      w0
      (sqrt (+ 1.0 (* -0.25 (* (* M (* (/ D d) (/ D l))) (/ h (/ d M))))))))))
M = abs(M);
D = abs(D);
assert(M < D);
double code(double w0, double M, double D, double h, double l, double d) {
	double t_0 = pow(((M * D) / (2.0 * d)), 2.0);
	double tmp;
	if (t_0 <= ((double) INFINITY)) {
		tmp = w0 * sqrt((1.0 - (h / (l / t_0))));
	} else {
		tmp = w0 * sqrt((1.0 + (-0.25 * ((M * ((D / d) * (D / l))) * (h / (d / M))))));
	}
	return tmp;
}
M = Math.abs(M);
D = Math.abs(D);
assert M < D;
public static double code(double w0, double M, double D, double h, double l, double d) {
	double t_0 = Math.pow(((M * D) / (2.0 * d)), 2.0);
	double tmp;
	if (t_0 <= Double.POSITIVE_INFINITY) {
		tmp = w0 * Math.sqrt((1.0 - (h / (l / t_0))));
	} else {
		tmp = w0 * Math.sqrt((1.0 + (-0.25 * ((M * ((D / d) * (D / l))) * (h / (d / M))))));
	}
	return tmp;
}
M = abs(M)
D = abs(D)
[M, D] = sort([M, D])
def code(w0, M, D, h, l, d):
	t_0 = math.pow(((M * D) / (2.0 * d)), 2.0)
	tmp = 0
	if t_0 <= math.inf:
		tmp = w0 * math.sqrt((1.0 - (h / (l / t_0))))
	else:
		tmp = w0 * math.sqrt((1.0 + (-0.25 * ((M * ((D / d) * (D / l))) * (h / (d / M))))))
	return tmp
M = abs(M)
D = abs(D)
M, D = sort([M, D])
function code(w0, M, D, h, l, d)
	t_0 = Float64(Float64(M * D) / Float64(2.0 * d)) ^ 2.0
	tmp = 0.0
	if (t_0 <= Inf)
		tmp = Float64(w0 * sqrt(Float64(1.0 - Float64(h / Float64(l / t_0)))));
	else
		tmp = Float64(w0 * sqrt(Float64(1.0 + Float64(-0.25 * Float64(Float64(M * Float64(Float64(D / d) * Float64(D / l))) * Float64(h / Float64(d / M)))))));
	end
	return tmp
end
M = abs(M)
D = abs(D)
M, D = num2cell(sort([M, D])){:}
function tmp_2 = code(w0, M, D, h, l, d)
	t_0 = ((M * D) / (2.0 * d)) ^ 2.0;
	tmp = 0.0;
	if (t_0 <= Inf)
		tmp = w0 * sqrt((1.0 - (h / (l / t_0))));
	else
		tmp = w0 * sqrt((1.0 + (-0.25 * ((M * ((D / d) * (D / l))) * (h / (d / M))))));
	end
	tmp_2 = tmp;
end
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
code[w0_, M_, D_, h_, l_, d_] := Block[{t$95$0 = N[Power[N[(N[(M * D), $MachinePrecision] / N[(2.0 * d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]}, If[LessEqual[t$95$0, Infinity], N[(w0 * N[Sqrt[N[(1.0 - N[(h / N[(l / t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(w0 * N[Sqrt[N[(1.0 + N[(-0.25 * N[(N[(M * N[(N[(D / d), $MachinePrecision] * N[(D / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(h / N[(d / M), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
M = |M|\\
D = |D|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\begin{array}{l}
t_0 := {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\\
\mathbf{if}\;t_0 \leq \infty:\\
\;\;\;\;w0 \cdot \sqrt{1 - \frac{h}{\frac{\ell}{t_0}}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (pow.f64 (/.f64 (*.f64 M D) (*.f64 2 d)) 2) < +inf.0

    1. Initial program 82.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if +inf.0 < (pow.f64 (/.f64 (*.f64 M D) (*.f64 2 d)) 2)

    1. Initial program 0.0%

      \[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]
    2. Step-by-step derivation
      1. *-commutative0.0%

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

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

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

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

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

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

        \[\leadsto w0 \cdot \sqrt{1 + \left(-0.25\right) \cdot \frac{{D}^{2} \cdot \left(h \cdot {M}^{2}\right)}{\color{blue}{\ell \cdot {d}^{2}}}} \]
      4. cancel-sign-sub-inv0.0%

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

        \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\frac{{D}^{2} \cdot \left(h \cdot {M}^{2}\right)}{\ell \cdot {d}^{2}} \cdot 0.25}} \]
      6. cancel-sign-sub-inv0.0%

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

        \[\leadsto w0 \cdot \sqrt{1 + \color{blue}{\left(-\frac{{D}^{2} \cdot \left(h \cdot {M}^{2}\right)}{\ell \cdot {d}^{2}} \cdot 0.25\right)}} \]
      8. distribute-rgt-neg-in0.0%

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

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

        \[\leadsto w0 \cdot \sqrt{1 + \color{blue}{\frac{\frac{D}{\frac{\ell}{D}} \cdot h}{\frac{d \cdot d}{M \cdot M}}} \cdot -0.25} \]
      2. associate-/r/0.0%

        \[\leadsto w0 \cdot \sqrt{1 + \frac{\color{blue}{\left(\frac{D}{\ell} \cdot D\right)} \cdot h}{\frac{d \cdot d}{M \cdot M}} \cdot -0.25} \]
      3. times-frac100.0%

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

      \[\leadsto w0 \cdot \sqrt{1 + \color{blue}{\frac{\left(\frac{D}{\ell} \cdot D\right) \cdot h}{\frac{d}{M} \cdot \frac{d}{M}}} \cdot -0.25} \]
    9. Step-by-step derivation
      1. times-frac100.0%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto w0 \cdot \sqrt{1 + \left(\left(M \cdot \color{blue}{\left(\frac{D}{d} \cdot \frac{D}{\ell}\right)}\right) \cdot \frac{h}{\frac{d}{M}}\right) \cdot -0.25} \]
    13. Simplified8.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \leq \infty:\\ \;\;\;\;w0 \cdot \sqrt{1 - \frac{h}{\frac{\ell}{{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}}}}\\ \mathbf{else}:\\ \;\;\;\;w0 \cdot \sqrt{1 + -0.25 \cdot \left(\left(M \cdot \left(\frac{D}{d} \cdot \frac{D}{\ell}\right)\right) \cdot \frac{h}{\frac{d}{M}}\right)}\\ \end{array} \]

Alternative 4: 88.1% accurate, 0.7× speedup?

\[\begin{array}{l} M = |M|\\ D = |D|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ \begin{array}{l} \mathbf{if}\;{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \leq 10^{+61}:\\ \;\;\;\;w0 \cdot \sqrt{1 - \frac{h \cdot {\left(M \cdot \left(D \cdot \frac{0.5}{d}\right)\right)}^{2}}{\ell}}\\ \mathbf{else}:\\ \;\;\;\;w0 \cdot \sqrt{1 + \frac{D \cdot h}{\frac{\ell}{D} \cdot \left(\frac{d}{M} \cdot \frac{d}{M}\right)} \cdot -0.25}\\ \end{array} \end{array} \]
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
(FPCore (w0 M D h l d)
 :precision binary64
 (if (<= (pow (/ (* M D) (* 2.0 d)) 2.0) 1e+61)
   (* w0 (sqrt (- 1.0 (/ (* h (pow (* M (* D (/ 0.5 d))) 2.0)) l))))
   (*
    w0
    (sqrt (+ 1.0 (* (/ (* D h) (* (/ l D) (* (/ d M) (/ d M)))) -0.25))))))
M = abs(M);
D = abs(D);
assert(M < D);
double code(double w0, double M, double D, double h, double l, double d) {
	double tmp;
	if (pow(((M * D) / (2.0 * d)), 2.0) <= 1e+61) {
		tmp = w0 * sqrt((1.0 - ((h * pow((M * (D * (0.5 / d))), 2.0)) / l)));
	} else {
		tmp = w0 * sqrt((1.0 + (((D * h) / ((l / D) * ((d / M) * (d / M)))) * -0.25)));
	}
	return tmp;
}
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
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
    real(8) :: tmp
    if ((((m * d) / (2.0d0 * d_1)) ** 2.0d0) <= 1d+61) then
        tmp = w0 * sqrt((1.0d0 - ((h * ((m * (d * (0.5d0 / d_1))) ** 2.0d0)) / l)))
    else
        tmp = w0 * sqrt((1.0d0 + (((d * h) / ((l / d) * ((d_1 / m) * (d_1 / m)))) * (-0.25d0))))
    end if
    code = tmp
end function
M = Math.abs(M);
D = Math.abs(D);
assert M < D;
public static double code(double w0, double M, double D, double h, double l, double d) {
	double tmp;
	if (Math.pow(((M * D) / (2.0 * d)), 2.0) <= 1e+61) {
		tmp = w0 * Math.sqrt((1.0 - ((h * Math.pow((M * (D * (0.5 / d))), 2.0)) / l)));
	} else {
		tmp = w0 * Math.sqrt((1.0 + (((D * h) / ((l / D) * ((d / M) * (d / M)))) * -0.25)));
	}
	return tmp;
}
M = abs(M)
D = abs(D)
[M, D] = sort([M, D])
def code(w0, M, D, h, l, d):
	tmp = 0
	if math.pow(((M * D) / (2.0 * d)), 2.0) <= 1e+61:
		tmp = w0 * math.sqrt((1.0 - ((h * math.pow((M * (D * (0.5 / d))), 2.0)) / l)))
	else:
		tmp = w0 * math.sqrt((1.0 + (((D * h) / ((l / D) * ((d / M) * (d / M)))) * -0.25)))
	return tmp
M = abs(M)
D = abs(D)
M, D = sort([M, D])
function code(w0, M, D, h, l, d)
	tmp = 0.0
	if ((Float64(Float64(M * D) / Float64(2.0 * d)) ^ 2.0) <= 1e+61)
		tmp = Float64(w0 * sqrt(Float64(1.0 - Float64(Float64(h * (Float64(M * Float64(D * Float64(0.5 / d))) ^ 2.0)) / l))));
	else
		tmp = Float64(w0 * sqrt(Float64(1.0 + Float64(Float64(Float64(D * h) / Float64(Float64(l / D) * Float64(Float64(d / M) * Float64(d / M)))) * -0.25))));
	end
	return tmp
end
M = abs(M)
D = abs(D)
M, D = num2cell(sort([M, D])){:}
function tmp_2 = code(w0, M, D, h, l, d)
	tmp = 0.0;
	if ((((M * D) / (2.0 * d)) ^ 2.0) <= 1e+61)
		tmp = w0 * sqrt((1.0 - ((h * ((M * (D * (0.5 / d))) ^ 2.0)) / l)));
	else
		tmp = w0 * sqrt((1.0 + (((D * h) / ((l / D) * ((d / M) * (d / M)))) * -0.25)));
	end
	tmp_2 = tmp;
end
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
code[w0_, M_, D_, h_, l_, d_] := If[LessEqual[N[Power[N[(N[(M * D), $MachinePrecision] / N[(2.0 * d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision], 1e+61], N[(w0 * N[Sqrt[N[(1.0 - N[(N[(h * N[Power[N[(M * N[(D * N[(0.5 / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(w0 * N[Sqrt[N[(1.0 + N[(N[(N[(D * h), $MachinePrecision] / N[(N[(l / D), $MachinePrecision] * N[(N[(d / M), $MachinePrecision] * N[(d / M), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
M = |M|\\
D = |D|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\begin{array}{l}
\mathbf{if}\;{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \leq 10^{+61}:\\
\;\;\;\;w0 \cdot \sqrt{1 - \frac{h \cdot {\left(M \cdot \left(D \cdot \frac{0.5}{d}\right)\right)}^{2}}{\ell}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (pow.f64 (/.f64 (*.f64 M D) (*.f64 2 d)) 2) < 9.99999999999999949e60

    1. Initial program 92.5%

      \[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]
    2. Step-by-step derivation
      1. *-commutative92.5%

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

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

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

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

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

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

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

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

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

        \[\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}} \]
      8. metadata-eval99.9%

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

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

    if 9.99999999999999949e60 < (pow.f64 (/.f64 (*.f64 M D) (*.f64 2 d)) 2)

    1. Initial program 61.6%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto w0 \cdot \sqrt{1 + \color{blue}{\left(-\frac{{D}^{2} \cdot \left(h \cdot {M}^{2}\right)}{\ell \cdot {d}^{2}} \cdot 0.25\right)}} \]
      8. distribute-rgt-neg-in36.2%

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

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

        \[\leadsto w0 \cdot \sqrt{1 + \color{blue}{\frac{D \cdot h}{\frac{\ell}{D} \cdot \frac{d \cdot d}{M \cdot M}}} \cdot -0.25} \]
      2. times-frac66.3%

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

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

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

Alternative 5: 81.4% accurate, 1.8× speedup?

\[\begin{array}{l} M = |M|\\ D = |D|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ \begin{array}{l} \mathbf{if}\;h \leq -2 \cdot 10^{+103}:\\ \;\;\;\;w0 \cdot \sqrt{1 + -0.25 \cdot \left(\left(M \cdot \left(\frac{D}{d} \cdot \frac{D}{\ell}\right)\right) \cdot \frac{h}{\frac{d}{M}}\right)}\\ \mathbf{else}:\\ \;\;\;\;w0 \cdot \left(1 + \left(D \cdot \frac{\frac{D}{\frac{\frac{d}{M} \cdot \frac{d}{M}}{h}}}{\ell}\right) \cdot -0.125\right)\\ \end{array} \end{array} \]
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
(FPCore (w0 M D h l d)
 :precision binary64
 (if (<= h -2e+103)
   (* w0 (sqrt (+ 1.0 (* -0.25 (* (* M (* (/ D d) (/ D l))) (/ h (/ d M)))))))
   (* w0 (+ 1.0 (* (* D (/ (/ D (/ (* (/ d M) (/ d M)) h)) l)) -0.125)))))
M = abs(M);
D = abs(D);
assert(M < D);
double code(double w0, double M, double D, double h, double l, double d) {
	double tmp;
	if (h <= -2e+103) {
		tmp = w0 * sqrt((1.0 + (-0.25 * ((M * ((D / d) * (D / l))) * (h / (d / M))))));
	} else {
		tmp = w0 * (1.0 + ((D * ((D / (((d / M) * (d / M)) / h)) / l)) * -0.125));
	}
	return tmp;
}
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
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
    real(8) :: tmp
    if (h <= (-2d+103)) then
        tmp = w0 * sqrt((1.0d0 + ((-0.25d0) * ((m * ((d / d_1) * (d / l))) * (h / (d_1 / m))))))
    else
        tmp = w0 * (1.0d0 + ((d * ((d / (((d_1 / m) * (d_1 / m)) / h)) / l)) * (-0.125d0)))
    end if
    code = tmp
end function
M = Math.abs(M);
D = Math.abs(D);
assert M < D;
public static double code(double w0, double M, double D, double h, double l, double d) {
	double tmp;
	if (h <= -2e+103) {
		tmp = w0 * Math.sqrt((1.0 + (-0.25 * ((M * ((D / d) * (D / l))) * (h / (d / M))))));
	} else {
		tmp = w0 * (1.0 + ((D * ((D / (((d / M) * (d / M)) / h)) / l)) * -0.125));
	}
	return tmp;
}
M = abs(M)
D = abs(D)
[M, D] = sort([M, D])
def code(w0, M, D, h, l, d):
	tmp = 0
	if h <= -2e+103:
		tmp = w0 * math.sqrt((1.0 + (-0.25 * ((M * ((D / d) * (D / l))) * (h / (d / M))))))
	else:
		tmp = w0 * (1.0 + ((D * ((D / (((d / M) * (d / M)) / h)) / l)) * -0.125))
	return tmp
M = abs(M)
D = abs(D)
M, D = sort([M, D])
function code(w0, M, D, h, l, d)
	tmp = 0.0
	if (h <= -2e+103)
		tmp = Float64(w0 * sqrt(Float64(1.0 + Float64(-0.25 * Float64(Float64(M * Float64(Float64(D / d) * Float64(D / l))) * Float64(h / Float64(d / M)))))));
	else
		tmp = Float64(w0 * Float64(1.0 + Float64(Float64(D * Float64(Float64(D / Float64(Float64(Float64(d / M) * Float64(d / M)) / h)) / l)) * -0.125)));
	end
	return tmp
end
M = abs(M)
D = abs(D)
M, D = num2cell(sort([M, D])){:}
function tmp_2 = code(w0, M, D, h, l, d)
	tmp = 0.0;
	if (h <= -2e+103)
		tmp = w0 * sqrt((1.0 + (-0.25 * ((M * ((D / d) * (D / l))) * (h / (d / M))))));
	else
		tmp = w0 * (1.0 + ((D * ((D / (((d / M) * (d / M)) / h)) / l)) * -0.125));
	end
	tmp_2 = tmp;
end
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
code[w0_, M_, D_, h_, l_, d_] := If[LessEqual[h, -2e+103], N[(w0 * N[Sqrt[N[(1.0 + N[(-0.25 * N[(N[(M * N[(N[(D / d), $MachinePrecision] * N[(D / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(h / N[(d / M), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(w0 * N[(1.0 + N[(N[(D * N[(N[(D / N[(N[(N[(d / M), $MachinePrecision] * N[(d / M), $MachinePrecision]), $MachinePrecision] / h), $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision] * -0.125), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
M = |M|\\
D = |D|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\begin{array}{l}
\mathbf{if}\;h \leq -2 \cdot 10^{+103}:\\
\;\;\;\;w0 \cdot \sqrt{1 + -0.25 \cdot \left(\left(M \cdot \left(\frac{D}{d} \cdot \frac{D}{\ell}\right)\right) \cdot \frac{h}{\frac{d}{M}}\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if h < -2e103

    1. Initial program 76.0%

      \[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]
    2. Step-by-step derivation
      1. *-commutative76.0%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto w0 \cdot \sqrt{1 + \color{blue}{\left(-\frac{{D}^{2} \cdot \left(h \cdot {M}^{2}\right)}{\ell \cdot {d}^{2}} \cdot 0.25\right)}} \]
      8. distribute-rgt-neg-in58.1%

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

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

        \[\leadsto w0 \cdot \sqrt{1 + \color{blue}{\frac{\frac{D}{\frac{\ell}{D}} \cdot h}{\frac{d \cdot d}{M \cdot M}}} \cdot -0.25} \]
      2. associate-/r/58.2%

        \[\leadsto w0 \cdot \sqrt{1 + \frac{\color{blue}{\left(\frac{D}{\ell} \cdot D\right)} \cdot h}{\frac{d \cdot d}{M \cdot M}} \cdot -0.25} \]
      3. times-frac75.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto w0 \cdot \sqrt{1 + \left(\left(M \cdot \color{blue}{\left(\frac{D}{d} \cdot \frac{D}{\ell}\right)}\right) \cdot \frac{h}{\frac{d}{M}}\right) \cdot -0.25} \]
    13. Simplified76.3%

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

    if -2e103 < h

    1. Initial program 83.7%

      \[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]
    2. Step-by-step derivation
      1. *-commutative83.7%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto w0 \cdot \left(1 + \left(\frac{D \cdot D}{d \cdot d} \cdot \frac{\color{blue}{\left(M \cdot M\right)} \cdot h}{\ell}\right) \cdot -0.125\right) \]
    6. Simplified53.7%

      \[\leadsto w0 \cdot \color{blue}{\left(1 + \left(\frac{D \cdot D}{d \cdot d} \cdot \frac{\left(M \cdot M\right) \cdot h}{\ell}\right) \cdot -0.125\right)} \]
    7. Taylor expanded in D around 0 51.9%

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

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

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

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

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

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

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

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

        \[\leadsto w0 \cdot \left(1 + \color{blue}{\left(D \cdot \left(\frac{D}{\ell} \cdot \left(\frac{h}{d \cdot d} \cdot \left(M \cdot M\right)\right)\right)\right)} \cdot -0.125\right) \]
      9. *-commutative64.7%

        \[\leadsto w0 \cdot \left(1 + \left(D \cdot \color{blue}{\left(\left(\frac{h}{d \cdot d} \cdot \left(M \cdot M\right)\right) \cdot \frac{D}{\ell}\right)}\right) \cdot -0.125\right) \]
      10. associate-*r/67.7%

        \[\leadsto w0 \cdot \left(1 + \left(D \cdot \color{blue}{\frac{\left(\frac{h}{d \cdot d} \cdot \left(M \cdot M\right)\right) \cdot D}{\ell}}\right) \cdot -0.125\right) \]
      11. *-commutative67.7%

        \[\leadsto w0 \cdot \left(1 + \left(D \cdot \frac{\color{blue}{\left(\left(M \cdot M\right) \cdot \frac{h}{d \cdot d}\right)} \cdot D}{\ell}\right) \cdot -0.125\right) \]
      12. associate-*l*68.5%

        \[\leadsto w0 \cdot \left(1 + \left(D \cdot \frac{\color{blue}{\left(M \cdot M\right) \cdot \left(\frac{h}{d \cdot d} \cdot D\right)}}{\ell}\right) \cdot -0.125\right) \]
      13. *-commutative68.5%

        \[\leadsto w0 \cdot \left(1 + \left(D \cdot \frac{\left(M \cdot M\right) \cdot \color{blue}{\left(D \cdot \frac{h}{d \cdot d}\right)}}{\ell}\right) \cdot -0.125\right) \]
      14. unpow268.5%

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

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

        \[\leadsto w0 \cdot \left(1 + \left(D \cdot \frac{\left(M \cdot M\right) \cdot \frac{D \cdot h}{\color{blue}{d \cdot d}}}{\ell}\right) \cdot -0.125\right) \]
    9. Simplified66.9%

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

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

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

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

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

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

        \[\leadsto w0 \cdot \left(1 + \left(D \cdot \frac{\frac{D}{\frac{\frac{\color{blue}{d \cdot d}}{M \cdot M}}{h}}}{\ell}\right) \cdot -0.125\right) \]
      6. times-frac78.8%

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

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

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

        \[\leadsto w0 \cdot \left(1 + \left(D \cdot \frac{\frac{D}{\frac{\color{blue}{\frac{d}{M} \cdot \frac{d}{M}}}{h}}}{\ell}\right) \cdot -0.125\right) \]
    14. Applied egg-rr78.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;h \leq -2 \cdot 10^{+103}:\\ \;\;\;\;w0 \cdot \sqrt{1 + -0.25 \cdot \left(\left(M \cdot \left(\frac{D}{d} \cdot \frac{D}{\ell}\right)\right) \cdot \frac{h}{\frac{d}{M}}\right)}\\ \mathbf{else}:\\ \;\;\;\;w0 \cdot \left(1 + \left(D \cdot \frac{\frac{D}{\frac{\frac{d}{M} \cdot \frac{d}{M}}{h}}}{\ell}\right) \cdot -0.125\right)\\ \end{array} \]

Alternative 6: 78.9% accurate, 1.8× speedup?

\[\begin{array}{l} M = |M|\\ D = |D|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ \begin{array}{l} \mathbf{if}\;d \leq 4.8 \cdot 10^{-90}:\\ \;\;\;\;w0 \cdot \sqrt{1 + -0.25 \cdot \left(\frac{h}{\frac{d}{M}} \cdot \frac{D \cdot \frac{D}{\ell}}{\frac{d}{M}}\right)}\\ \mathbf{else}:\\ \;\;\;\;w0 \cdot \left(1 + \left(D \cdot \frac{\frac{D}{\frac{\frac{d}{M} \cdot \frac{d}{M}}{h}}}{\ell}\right) \cdot -0.125\right)\\ \end{array} \end{array} \]
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
(FPCore (w0 M D h l d)
 :precision binary64
 (if (<= d 4.8e-90)
   (* w0 (sqrt (+ 1.0 (* -0.25 (* (/ h (/ d M)) (/ (* D (/ D l)) (/ d M)))))))
   (* w0 (+ 1.0 (* (* D (/ (/ D (/ (* (/ d M) (/ d M)) h)) l)) -0.125)))))
M = abs(M);
D = abs(D);
assert(M < D);
double code(double w0, double M, double D, double h, double l, double d) {
	double tmp;
	if (d <= 4.8e-90) {
		tmp = w0 * sqrt((1.0 + (-0.25 * ((h / (d / M)) * ((D * (D / l)) / (d / M))))));
	} else {
		tmp = w0 * (1.0 + ((D * ((D / (((d / M) * (d / M)) / h)) / l)) * -0.125));
	}
	return tmp;
}
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
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
    real(8) :: tmp
    if (d_1 <= 4.8d-90) then
        tmp = w0 * sqrt((1.0d0 + ((-0.25d0) * ((h / (d_1 / m)) * ((d * (d / l)) / (d_1 / m))))))
    else
        tmp = w0 * (1.0d0 + ((d * ((d / (((d_1 / m) * (d_1 / m)) / h)) / l)) * (-0.125d0)))
    end if
    code = tmp
end function
M = Math.abs(M);
D = Math.abs(D);
assert M < D;
public static double code(double w0, double M, double D, double h, double l, double d) {
	double tmp;
	if (d <= 4.8e-90) {
		tmp = w0 * Math.sqrt((1.0 + (-0.25 * ((h / (d / M)) * ((D * (D / l)) / (d / M))))));
	} else {
		tmp = w0 * (1.0 + ((D * ((D / (((d / M) * (d / M)) / h)) / l)) * -0.125));
	}
	return tmp;
}
M = abs(M)
D = abs(D)
[M, D] = sort([M, D])
def code(w0, M, D, h, l, d):
	tmp = 0
	if d <= 4.8e-90:
		tmp = w0 * math.sqrt((1.0 + (-0.25 * ((h / (d / M)) * ((D * (D / l)) / (d / M))))))
	else:
		tmp = w0 * (1.0 + ((D * ((D / (((d / M) * (d / M)) / h)) / l)) * -0.125))
	return tmp
M = abs(M)
D = abs(D)
M, D = sort([M, D])
function code(w0, M, D, h, l, d)
	tmp = 0.0
	if (d <= 4.8e-90)
		tmp = Float64(w0 * sqrt(Float64(1.0 + Float64(-0.25 * Float64(Float64(h / Float64(d / M)) * Float64(Float64(D * Float64(D / l)) / Float64(d / M)))))));
	else
		tmp = Float64(w0 * Float64(1.0 + Float64(Float64(D * Float64(Float64(D / Float64(Float64(Float64(d / M) * Float64(d / M)) / h)) / l)) * -0.125)));
	end
	return tmp
end
M = abs(M)
D = abs(D)
M, D = num2cell(sort([M, D])){:}
function tmp_2 = code(w0, M, D, h, l, d)
	tmp = 0.0;
	if (d <= 4.8e-90)
		tmp = w0 * sqrt((1.0 + (-0.25 * ((h / (d / M)) * ((D * (D / l)) / (d / M))))));
	else
		tmp = w0 * (1.0 + ((D * ((D / (((d / M) * (d / M)) / h)) / l)) * -0.125));
	end
	tmp_2 = tmp;
end
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
code[w0_, M_, D_, h_, l_, d_] := If[LessEqual[d, 4.8e-90], N[(w0 * N[Sqrt[N[(1.0 + N[(-0.25 * N[(N[(h / N[(d / M), $MachinePrecision]), $MachinePrecision] * N[(N[(D * N[(D / l), $MachinePrecision]), $MachinePrecision] / N[(d / M), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(w0 * N[(1.0 + N[(N[(D * N[(N[(D / N[(N[(N[(d / M), $MachinePrecision] * N[(d / M), $MachinePrecision]), $MachinePrecision] / h), $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision] * -0.125), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
M = |M|\\
D = |D|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\begin{array}{l}
\mathbf{if}\;d \leq 4.8 \cdot 10^{-90}:\\
\;\;\;\;w0 \cdot \sqrt{1 + -0.25 \cdot \left(\frac{h}{\frac{d}{M}} \cdot \frac{D \cdot \frac{D}{\ell}}{\frac{d}{M}}\right)}\\

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


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

    1. Initial program 81.6%

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

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

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

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

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

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

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

        \[\leadsto w0 \cdot \sqrt{1 + \left(-0.25\right) \cdot \frac{{D}^{2} \cdot \left(h \cdot {M}^{2}\right)}{\color{blue}{\ell \cdot {d}^{2}}}} \]
      4. cancel-sign-sub-inv52.0%

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

        \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\frac{{D}^{2} \cdot \left(h \cdot {M}^{2}\right)}{\ell \cdot {d}^{2}} \cdot 0.25}} \]
      6. cancel-sign-sub-inv52.0%

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

        \[\leadsto w0 \cdot \sqrt{1 + \color{blue}{\left(-\frac{{D}^{2} \cdot \left(h \cdot {M}^{2}\right)}{\ell \cdot {d}^{2}} \cdot 0.25\right)}} \]
      8. distribute-rgt-neg-in52.0%

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

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

        \[\leadsto w0 \cdot \sqrt{1 + \color{blue}{\frac{\frac{D}{\frac{\ell}{D}} \cdot h}{\frac{d \cdot d}{M \cdot M}}} \cdot -0.25} \]
      2. associate-/r/54.0%

        \[\leadsto w0 \cdot \sqrt{1 + \frac{\color{blue}{\left(\frac{D}{\ell} \cdot D\right)} \cdot h}{\frac{d \cdot d}{M \cdot M}} \cdot -0.25} \]
      3. times-frac70.9%

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

      \[\leadsto w0 \cdot \sqrt{1 + \color{blue}{\frac{\left(\frac{D}{\ell} \cdot D\right) \cdot h}{\frac{d}{M} \cdot \frac{d}{M}}} \cdot -0.25} \]
    9. Step-by-step derivation
      1. times-frac79.8%

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

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

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

    if 4.8000000000000003e-90 < d

    1. Initial program 83.9%

      \[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]
    2. Step-by-step derivation
      1. *-commutative83.9%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto w0 \cdot \color{blue}{\left(1 + \left(\frac{D \cdot D}{d \cdot d} \cdot \frac{\left(M \cdot M\right) \cdot h}{\ell}\right) \cdot -0.125\right)} \]
    7. Taylor expanded in D around 0 55.2%

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

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

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

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

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

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

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

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

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

        \[\leadsto w0 \cdot \left(1 + \left(D \cdot \color{blue}{\left(\left(\frac{h}{d \cdot d} \cdot \left(M \cdot M\right)\right) \cdot \frac{D}{\ell}\right)}\right) \cdot -0.125\right) \]
      10. associate-*r/74.1%

        \[\leadsto w0 \cdot \left(1 + \left(D \cdot \color{blue}{\frac{\left(\frac{h}{d \cdot d} \cdot \left(M \cdot M\right)\right) \cdot D}{\ell}}\right) \cdot -0.125\right) \]
      11. *-commutative74.1%

        \[\leadsto w0 \cdot \left(1 + \left(D \cdot \frac{\color{blue}{\left(\left(M \cdot M\right) \cdot \frac{h}{d \cdot d}\right)} \cdot D}{\ell}\right) \cdot -0.125\right) \]
      12. associate-*l*76.0%

        \[\leadsto w0 \cdot \left(1 + \left(D \cdot \frac{\color{blue}{\left(M \cdot M\right) \cdot \left(\frac{h}{d \cdot d} \cdot D\right)}}{\ell}\right) \cdot -0.125\right) \]
      13. *-commutative76.0%

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

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

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

        \[\leadsto w0 \cdot \left(1 + \left(D \cdot \frac{\left(M \cdot M\right) \cdot \frac{D \cdot h}{\color{blue}{d \cdot d}}}{\ell}\right) \cdot -0.125\right) \]
    9. Simplified73.9%

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

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

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

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

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

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

        \[\leadsto w0 \cdot \left(1 + \left(D \cdot \frac{\frac{D}{\frac{\frac{\color{blue}{d \cdot d}}{M \cdot M}}{h}}}{\ell}\right) \cdot -0.125\right) \]
      6. times-frac83.4%

        \[\leadsto w0 \cdot \left(1 + \left(D \cdot \frac{\frac{D}{\frac{\color{blue}{\frac{d}{M} \cdot \frac{d}{M}}}{h}}}{\ell}\right) \cdot -0.125\right) \]
      7. unpow283.4%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq 4.8 \cdot 10^{-90}:\\ \;\;\;\;w0 \cdot \sqrt{1 + -0.25 \cdot \left(\frac{h}{\frac{d}{M}} \cdot \frac{D \cdot \frac{D}{\ell}}{\frac{d}{M}}\right)}\\ \mathbf{else}:\\ \;\;\;\;w0 \cdot \left(1 + \left(D \cdot \frac{\frac{D}{\frac{\frac{d}{M} \cdot \frac{d}{M}}{h}}}{\ell}\right) \cdot -0.125\right)\\ \end{array} \]

Alternative 7: 80.9% accurate, 1.8× speedup?

\[\begin{array}{l} M = |M|\\ D = |D|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ \begin{array}{l} t_0 := \frac{d}{M} \cdot \frac{d}{M}\\ \mathbf{if}\;d \leq 4 \cdot 10^{-13}:\\ \;\;\;\;w0 \cdot \sqrt{1 + \frac{D \cdot h}{\frac{\ell}{D} \cdot t_0} \cdot -0.25}\\ \mathbf{else}:\\ \;\;\;\;w0 \cdot \left(1 + \left(D \cdot \frac{\frac{D}{\frac{t_0}{h}}}{\ell}\right) \cdot -0.125\right)\\ \end{array} \end{array} \]
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
(FPCore (w0 M D h l d)
 :precision binary64
 (let* ((t_0 (* (/ d M) (/ d M))))
   (if (<= d 4e-13)
     (* w0 (sqrt (+ 1.0 (* (/ (* D h) (* (/ l D) t_0)) -0.25))))
     (* w0 (+ 1.0 (* (* D (/ (/ D (/ t_0 h)) l)) -0.125))))))
M = abs(M);
D = abs(D);
assert(M < D);
double code(double w0, double M, double D, double h, double l, double d) {
	double t_0 = (d / M) * (d / M);
	double tmp;
	if (d <= 4e-13) {
		tmp = w0 * sqrt((1.0 + (((D * h) / ((l / D) * t_0)) * -0.25)));
	} else {
		tmp = w0 * (1.0 + ((D * ((D / (t_0 / h)) / l)) * -0.125));
	}
	return tmp;
}
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
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
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (d_1 / m) * (d_1 / m)
    if (d_1 <= 4d-13) then
        tmp = w0 * sqrt((1.0d0 + (((d * h) / ((l / d) * t_0)) * (-0.25d0))))
    else
        tmp = w0 * (1.0d0 + ((d * ((d / (t_0 / h)) / l)) * (-0.125d0)))
    end if
    code = tmp
end function
M = Math.abs(M);
D = Math.abs(D);
assert M < D;
public static double code(double w0, double M, double D, double h, double l, double d) {
	double t_0 = (d / M) * (d / M);
	double tmp;
	if (d <= 4e-13) {
		tmp = w0 * Math.sqrt((1.0 + (((D * h) / ((l / D) * t_0)) * -0.25)));
	} else {
		tmp = w0 * (1.0 + ((D * ((D / (t_0 / h)) / l)) * -0.125));
	}
	return tmp;
}
M = abs(M)
D = abs(D)
[M, D] = sort([M, D])
def code(w0, M, D, h, l, d):
	t_0 = (d / M) * (d / M)
	tmp = 0
	if d <= 4e-13:
		tmp = w0 * math.sqrt((1.0 + (((D * h) / ((l / D) * t_0)) * -0.25)))
	else:
		tmp = w0 * (1.0 + ((D * ((D / (t_0 / h)) / l)) * -0.125))
	return tmp
M = abs(M)
D = abs(D)
M, D = sort([M, D])
function code(w0, M, D, h, l, d)
	t_0 = Float64(Float64(d / M) * Float64(d / M))
	tmp = 0.0
	if (d <= 4e-13)
		tmp = Float64(w0 * sqrt(Float64(1.0 + Float64(Float64(Float64(D * h) / Float64(Float64(l / D) * t_0)) * -0.25))));
	else
		tmp = Float64(w0 * Float64(1.0 + Float64(Float64(D * Float64(Float64(D / Float64(t_0 / h)) / l)) * -0.125)));
	end
	return tmp
end
M = abs(M)
D = abs(D)
M, D = num2cell(sort([M, D])){:}
function tmp_2 = code(w0, M, D, h, l, d)
	t_0 = (d / M) * (d / M);
	tmp = 0.0;
	if (d <= 4e-13)
		tmp = w0 * sqrt((1.0 + (((D * h) / ((l / D) * t_0)) * -0.25)));
	else
		tmp = w0 * (1.0 + ((D * ((D / (t_0 / h)) / l)) * -0.125));
	end
	tmp_2 = tmp;
end
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
code[w0_, M_, D_, h_, l_, d_] := Block[{t$95$0 = N[(N[(d / M), $MachinePrecision] * N[(d / M), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, 4e-13], N[(w0 * N[Sqrt[N[(1.0 + N[(N[(N[(D * h), $MachinePrecision] / N[(N[(l / D), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(w0 * N[(1.0 + N[(N[(D * N[(N[(D / N[(t$95$0 / h), $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision] * -0.125), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
M = |M|\\
D = |D|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\begin{array}{l}
t_0 := \frac{d}{M} \cdot \frac{d}{M}\\
\mathbf{if}\;d \leq 4 \cdot 10^{-13}:\\
\;\;\;\;w0 \cdot \sqrt{1 + \frac{D \cdot h}{\frac{\ell}{D} \cdot t_0} \cdot -0.25}\\

\mathbf{else}:\\
\;\;\;\;w0 \cdot \left(1 + \left(D \cdot \frac{\frac{D}{\frac{t_0}{h}}}{\ell}\right) \cdot -0.125\right)\\


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

    1. Initial program 81.8%

      \[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]
    2. Step-by-step derivation
      1. *-commutative81.8%

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

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

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

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

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

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

        \[\leadsto w0 \cdot \sqrt{1 + \left(-0.25\right) \cdot \frac{{D}^{2} \cdot \left(h \cdot {M}^{2}\right)}{\color{blue}{\ell \cdot {d}^{2}}}} \]
      4. cancel-sign-sub-inv52.5%

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

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

        \[\leadsto w0 \cdot \sqrt{\color{blue}{1 + \left(-\frac{{D}^{2} \cdot \left(h \cdot {M}^{2}\right)}{\ell \cdot {d}^{2}}\right) \cdot 0.25}} \]
      7. distribute-lft-neg-in52.5%

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

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

      \[\leadsto \color{blue}{w0 \cdot \sqrt{1 + \left(\frac{D}{\frac{\ell}{D}} \cdot \frac{h}{\frac{d \cdot d}{M \cdot M}}\right) \cdot -0.25}} \]
    7. Step-by-step derivation
      1. frac-times62.0%

        \[\leadsto w0 \cdot \sqrt{1 + \color{blue}{\frac{D \cdot h}{\frac{\ell}{D} \cdot \frac{d \cdot d}{M \cdot M}}} \cdot -0.25} \]
      2. times-frac78.2%

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

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

    if 4.0000000000000001e-13 < d

    1. Initial program 83.9%

      \[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]
    2. Step-by-step derivation
      1. *-commutative83.9%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto w0 \cdot \left(1 + \left(\frac{D \cdot D}{d \cdot d} \cdot \frac{\color{blue}{\left(M \cdot M\right)} \cdot h}{\ell}\right) \cdot -0.125\right) \]
    6. Simplified55.8%

      \[\leadsto w0 \cdot \color{blue}{\left(1 + \left(\frac{D \cdot D}{d \cdot d} \cdot \frac{\left(M \cdot M\right) \cdot h}{\ell}\right) \cdot -0.125\right)} \]
    7. Taylor expanded in D around 0 54.7%

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

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

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

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

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

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

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

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

        \[\leadsto w0 \cdot \left(1 + \color{blue}{\left(D \cdot \left(\frac{D}{\ell} \cdot \left(\frac{h}{d \cdot d} \cdot \left(M \cdot M\right)\right)\right)\right)} \cdot -0.125\right) \]
      9. *-commutative71.3%

        \[\leadsto w0 \cdot \left(1 + \left(D \cdot \color{blue}{\left(\left(\frac{h}{d \cdot d} \cdot \left(M \cdot M\right)\right) \cdot \frac{D}{\ell}\right)}\right) \cdot -0.125\right) \]
      10. associate-*r/74.9%

        \[\leadsto w0 \cdot \left(1 + \left(D \cdot \color{blue}{\frac{\left(\frac{h}{d \cdot d} \cdot \left(M \cdot M\right)\right) \cdot D}{\ell}}\right) \cdot -0.125\right) \]
      11. *-commutative74.9%

        \[\leadsto w0 \cdot \left(1 + \left(D \cdot \frac{\color{blue}{\left(\left(M \cdot M\right) \cdot \frac{h}{d \cdot d}\right)} \cdot D}{\ell}\right) \cdot -0.125\right) \]
      12. associate-*l*76.0%

        \[\leadsto w0 \cdot \left(1 + \left(D \cdot \frac{\color{blue}{\left(M \cdot M\right) \cdot \left(\frac{h}{d \cdot d} \cdot D\right)}}{\ell}\right) \cdot -0.125\right) \]
      13. *-commutative76.0%

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

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

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

        \[\leadsto w0 \cdot \left(1 + \left(D \cdot \frac{\left(M \cdot M\right) \cdot \frac{D \cdot h}{\color{blue}{d \cdot d}}}{\ell}\right) \cdot -0.125\right) \]
    9. Simplified72.4%

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

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

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

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

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

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

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

        \[\leadsto w0 \cdot \left(1 + \left(D \cdot \frac{\frac{D}{\frac{\color{blue}{\frac{d}{M} \cdot \frac{d}{M}}}{h}}}{\ell}\right) \cdot -0.125\right) \]
      7. unpow284.4%

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

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

        \[\leadsto w0 \cdot \left(1 + \left(D \cdot \frac{\frac{D}{\frac{\color{blue}{\frac{d}{M} \cdot \frac{d}{M}}}{h}}}{\ell}\right) \cdot -0.125\right) \]
    14. Applied egg-rr84.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq 4 \cdot 10^{-13}:\\ \;\;\;\;w0 \cdot \sqrt{1 + \frac{D \cdot h}{\frac{\ell}{D} \cdot \left(\frac{d}{M} \cdot \frac{d}{M}\right)} \cdot -0.25}\\ \mathbf{else}:\\ \;\;\;\;w0 \cdot \left(1 + \left(D \cdot \frac{\frac{D}{\frac{\frac{d}{M} \cdot \frac{d}{M}}{h}}}{\ell}\right) \cdot -0.125\right)\\ \end{array} \]

Alternative 8: 76.4% accurate, 9.4× speedup?

\[\begin{array}{l} M = |M|\\ D = |D|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ \begin{array}{l} \mathbf{if}\;M \leq 4 \cdot 10^{-122}:\\ \;\;\;\;w0\\ \mathbf{else}:\\ \;\;\;\;w0 \cdot \left(1 + -0.125 \cdot \left(D \cdot \left(\frac{D}{d \cdot d} \cdot \frac{h \cdot \left(M \cdot M\right)}{\ell}\right)\right)\right)\\ \end{array} \end{array} \]
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
(FPCore (w0 M D h l d)
 :precision binary64
 (if (<= M 4e-122)
   w0
   (* w0 (+ 1.0 (* -0.125 (* D (* (/ D (* d d)) (/ (* h (* M M)) l))))))))
M = abs(M);
D = abs(D);
assert(M < D);
double code(double w0, double M, double D, double h, double l, double d) {
	double tmp;
	if (M <= 4e-122) {
		tmp = w0;
	} else {
		tmp = w0 * (1.0 + (-0.125 * (D * ((D / (d * d)) * ((h * (M * M)) / l)))));
	}
	return tmp;
}
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
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
    real(8) :: tmp
    if (m <= 4d-122) then
        tmp = w0
    else
        tmp = w0 * (1.0d0 + ((-0.125d0) * (d * ((d / (d_1 * d_1)) * ((h * (m * m)) / l)))))
    end if
    code = tmp
end function
M = Math.abs(M);
D = Math.abs(D);
assert M < D;
public static double code(double w0, double M, double D, double h, double l, double d) {
	double tmp;
	if (M <= 4e-122) {
		tmp = w0;
	} else {
		tmp = w0 * (1.0 + (-0.125 * (D * ((D / (d * d)) * ((h * (M * M)) / l)))));
	}
	return tmp;
}
M = abs(M)
D = abs(D)
[M, D] = sort([M, D])
def code(w0, M, D, h, l, d):
	tmp = 0
	if M <= 4e-122:
		tmp = w0
	else:
		tmp = w0 * (1.0 + (-0.125 * (D * ((D / (d * d)) * ((h * (M * M)) / l)))))
	return tmp
M = abs(M)
D = abs(D)
M, D = sort([M, D])
function code(w0, M, D, h, l, d)
	tmp = 0.0
	if (M <= 4e-122)
		tmp = w0;
	else
		tmp = Float64(w0 * Float64(1.0 + Float64(-0.125 * Float64(D * Float64(Float64(D / Float64(d * d)) * Float64(Float64(h * Float64(M * M)) / l))))));
	end
	return tmp
end
M = abs(M)
D = abs(D)
M, D = num2cell(sort([M, D])){:}
function tmp_2 = code(w0, M, D, h, l, d)
	tmp = 0.0;
	if (M <= 4e-122)
		tmp = w0;
	else
		tmp = w0 * (1.0 + (-0.125 * (D * ((D / (d * d)) * ((h * (M * M)) / l)))));
	end
	tmp_2 = tmp;
end
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
code[w0_, M_, D_, h_, l_, d_] := If[LessEqual[M, 4e-122], w0, N[(w0 * N[(1.0 + N[(-0.125 * N[(D * N[(N[(D / N[(d * d), $MachinePrecision]), $MachinePrecision] * N[(N[(h * N[(M * M), $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
M = |M|\\
D = |D|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\begin{array}{l}
\mathbf{if}\;M \leq 4 \cdot 10^{-122}:\\
\;\;\;\;w0\\

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


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

    1. Initial program 83.7%

      \[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]
    2. Step-by-step derivation
      1. *-commutative83.7%

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

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

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

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

    if 4.00000000000000024e-122 < M

    1. Initial program 79.4%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto w0 \cdot \left(1 + \left(\frac{D \cdot D}{d \cdot d} \cdot \frac{\color{blue}{\left(M \cdot M\right)} \cdot h}{\ell}\right) \cdot -0.125\right) \]
    6. Simplified49.4%

      \[\leadsto w0 \cdot \color{blue}{\left(1 + \left(\frac{D \cdot D}{d \cdot d} \cdot \frac{\left(M \cdot M\right) \cdot h}{\ell}\right) \cdot -0.125\right)} \]
    7. Taylor expanded in D around 0 46.4%

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

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

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

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

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

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

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

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

        \[\leadsto w0 \cdot \left(1 + \color{blue}{\left(D \cdot \left(\frac{D}{\ell} \cdot \left(\frac{h}{d \cdot d} \cdot \left(M \cdot M\right)\right)\right)\right)} \cdot -0.125\right) \]
      9. *-commutative59.7%

        \[\leadsto w0 \cdot \left(1 + \left(D \cdot \color{blue}{\left(\left(\frac{h}{d \cdot d} \cdot \left(M \cdot M\right)\right) \cdot \frac{D}{\ell}\right)}\right) \cdot -0.125\right) \]
      10. associate-*r/61.2%

        \[\leadsto w0 \cdot \left(1 + \left(D \cdot \color{blue}{\frac{\left(\frac{h}{d \cdot d} \cdot \left(M \cdot M\right)\right) \cdot D}{\ell}}\right) \cdot -0.125\right) \]
      11. *-commutative61.2%

        \[\leadsto w0 \cdot \left(1 + \left(D \cdot \frac{\color{blue}{\left(\left(M \cdot M\right) \cdot \frac{h}{d \cdot d}\right)} \cdot D}{\ell}\right) \cdot -0.125\right) \]
      12. associate-*l*62.6%

        \[\leadsto w0 \cdot \left(1 + \left(D \cdot \frac{\color{blue}{\left(M \cdot M\right) \cdot \left(\frac{h}{d \cdot d} \cdot D\right)}}{\ell}\right) \cdot -0.125\right) \]
      13. *-commutative62.6%

        \[\leadsto w0 \cdot \left(1 + \left(D \cdot \frac{\left(M \cdot M\right) \cdot \color{blue}{\left(D \cdot \frac{h}{d \cdot d}\right)}}{\ell}\right) \cdot -0.125\right) \]
      14. unpow262.6%

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

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

        \[\leadsto w0 \cdot \left(1 + \left(D \cdot \frac{\left(M \cdot M\right) \cdot \frac{D \cdot h}{\color{blue}{d \cdot d}}}{\ell}\right) \cdot -0.125\right) \]
    9. Simplified62.5%

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

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

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

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

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

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

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

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

        \[\leadsto w0 \cdot \left(1 + \left(D \cdot \left(\frac{D}{d \cdot d} \cdot \frac{\color{blue}{\left(M \cdot M\right)} \cdot h}{\ell}\right)\right) \cdot -0.125\right) \]
      8. *-commutative59.7%

        \[\leadsto w0 \cdot \left(1 + \left(D \cdot \left(\frac{D}{d \cdot d} \cdot \frac{\color{blue}{h \cdot \left(M \cdot M\right)}}{\ell}\right)\right) \cdot -0.125\right) \]
    12. Simplified59.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;M \leq 4 \cdot 10^{-122}:\\ \;\;\;\;w0\\ \mathbf{else}:\\ \;\;\;\;w0 \cdot \left(1 + -0.125 \cdot \left(D \cdot \left(\frac{D}{d \cdot d} \cdot \frac{h \cdot \left(M \cdot M\right)}{\ell}\right)\right)\right)\\ \end{array} \]

Alternative 9: 76.4% accurate, 9.4× speedup?

\[\begin{array}{l} M = |M|\\ D = |D|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ \begin{array}{l} \mathbf{if}\;M \leq 6.6 \cdot 10^{-126}:\\ \;\;\;\;w0\\ \mathbf{else}:\\ \;\;\;\;w0 \cdot \left(1 + -0.125 \cdot \left(D \cdot \frac{\left(M \cdot M\right) \cdot \frac{D \cdot h}{d \cdot d}}{\ell}\right)\right)\\ \end{array} \end{array} \]
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
(FPCore (w0 M D h l d)
 :precision binary64
 (if (<= M 6.6e-126)
   w0
   (* w0 (+ 1.0 (* -0.125 (* D (/ (* (* M M) (/ (* D h) (* d d))) l)))))))
M = abs(M);
D = abs(D);
assert(M < D);
double code(double w0, double M, double D, double h, double l, double d) {
	double tmp;
	if (M <= 6.6e-126) {
		tmp = w0;
	} else {
		tmp = w0 * (1.0 + (-0.125 * (D * (((M * M) * ((D * h) / (d * d))) / l))));
	}
	return tmp;
}
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
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
    real(8) :: tmp
    if (m <= 6.6d-126) then
        tmp = w0
    else
        tmp = w0 * (1.0d0 + ((-0.125d0) * (d * (((m * m) * ((d * h) / (d_1 * d_1))) / l))))
    end if
    code = tmp
end function
M = Math.abs(M);
D = Math.abs(D);
assert M < D;
public static double code(double w0, double M, double D, double h, double l, double d) {
	double tmp;
	if (M <= 6.6e-126) {
		tmp = w0;
	} else {
		tmp = w0 * (1.0 + (-0.125 * (D * (((M * M) * ((D * h) / (d * d))) / l))));
	}
	return tmp;
}
M = abs(M)
D = abs(D)
[M, D] = sort([M, D])
def code(w0, M, D, h, l, d):
	tmp = 0
	if M <= 6.6e-126:
		tmp = w0
	else:
		tmp = w0 * (1.0 + (-0.125 * (D * (((M * M) * ((D * h) / (d * d))) / l))))
	return tmp
M = abs(M)
D = abs(D)
M, D = sort([M, D])
function code(w0, M, D, h, l, d)
	tmp = 0.0
	if (M <= 6.6e-126)
		tmp = w0;
	else
		tmp = Float64(w0 * Float64(1.0 + Float64(-0.125 * Float64(D * Float64(Float64(Float64(M * M) * Float64(Float64(D * h) / Float64(d * d))) / l)))));
	end
	return tmp
end
M = abs(M)
D = abs(D)
M, D = num2cell(sort([M, D])){:}
function tmp_2 = code(w0, M, D, h, l, d)
	tmp = 0.0;
	if (M <= 6.6e-126)
		tmp = w0;
	else
		tmp = w0 * (1.0 + (-0.125 * (D * (((M * M) * ((D * h) / (d * d))) / l))));
	end
	tmp_2 = tmp;
end
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
code[w0_, M_, D_, h_, l_, d_] := If[LessEqual[M, 6.6e-126], w0, N[(w0 * N[(1.0 + N[(-0.125 * N[(D * N[(N[(N[(M * M), $MachinePrecision] * N[(N[(D * h), $MachinePrecision] / N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
M = |M|\\
D = |D|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\begin{array}{l}
\mathbf{if}\;M \leq 6.6 \cdot 10^{-126}:\\
\;\;\;\;w0\\

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


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

    1. Initial program 83.6%

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

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

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

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

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

    if 6.6000000000000001e-126 < M

    1. Initial program 79.7%

      \[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]
    2. Step-by-step derivation
      1. *-commutative79.7%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto w0 \cdot \color{blue}{\left(1 + \left(\frac{D \cdot D}{d \cdot d} \cdot \frac{\left(M \cdot M\right) \cdot h}{\ell}\right) \cdot -0.125\right)} \]
    7. Taylor expanded in D around 0 47.1%

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

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

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

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

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

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

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

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

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

        \[\leadsto w0 \cdot \left(1 + \left(D \cdot \color{blue}{\left(\left(\frac{h}{d \cdot d} \cdot \left(M \cdot M\right)\right) \cdot \frac{D}{\ell}\right)}\right) \cdot -0.125\right) \]
      10. associate-*r/61.8%

        \[\leadsto w0 \cdot \left(1 + \left(D \cdot \color{blue}{\frac{\left(\frac{h}{d \cdot d} \cdot \left(M \cdot M\right)\right) \cdot D}{\ell}}\right) \cdot -0.125\right) \]
      11. *-commutative61.8%

        \[\leadsto w0 \cdot \left(1 + \left(D \cdot \frac{\color{blue}{\left(\left(M \cdot M\right) \cdot \frac{h}{d \cdot d}\right)} \cdot D}{\ell}\right) \cdot -0.125\right) \]
      12. associate-*l*63.2%

        \[\leadsto w0 \cdot \left(1 + \left(D \cdot \frac{\color{blue}{\left(M \cdot M\right) \cdot \left(\frac{h}{d \cdot d} \cdot D\right)}}{\ell}\right) \cdot -0.125\right) \]
      13. *-commutative63.2%

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

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

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

        \[\leadsto w0 \cdot \left(1 + \left(D \cdot \frac{\left(M \cdot M\right) \cdot \frac{D \cdot h}{\color{blue}{d \cdot d}}}{\ell}\right) \cdot -0.125\right) \]
    9. Simplified63.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;M \leq 6.6 \cdot 10^{-126}:\\ \;\;\;\;w0\\ \mathbf{else}:\\ \;\;\;\;w0 \cdot \left(1 + -0.125 \cdot \left(D \cdot \frac{\left(M \cdot M\right) \cdot \frac{D \cdot h}{d \cdot d}}{\ell}\right)\right)\\ \end{array} \]

Alternative 10: 78.0% accurate, 9.4× speedup?

\[\begin{array}{l} M = |M|\\ D = |D|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ \begin{array}{l} \mathbf{if}\;M \leq 3.5 \cdot 10^{-153}:\\ \;\;\;\;w0\\ \mathbf{else}:\\ \;\;\;\;w0 \cdot \left(1 + -0.125 \cdot \left(D \cdot \frac{\frac{M \cdot M}{d} \cdot \frac{D \cdot h}{d}}{\ell}\right)\right)\\ \end{array} \end{array} \]
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
(FPCore (w0 M D h l d)
 :precision binary64
 (if (<= M 3.5e-153)
   w0
   (* w0 (+ 1.0 (* -0.125 (* D (/ (* (/ (* M M) d) (/ (* D h) d)) l)))))))
M = abs(M);
D = abs(D);
assert(M < D);
double code(double w0, double M, double D, double h, double l, double d) {
	double tmp;
	if (M <= 3.5e-153) {
		tmp = w0;
	} else {
		tmp = w0 * (1.0 + (-0.125 * (D * ((((M * M) / d) * ((D * h) / d)) / l))));
	}
	return tmp;
}
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
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
    real(8) :: tmp
    if (m <= 3.5d-153) then
        tmp = w0
    else
        tmp = w0 * (1.0d0 + ((-0.125d0) * (d * ((((m * m) / d_1) * ((d * h) / d_1)) / l))))
    end if
    code = tmp
end function
M = Math.abs(M);
D = Math.abs(D);
assert M < D;
public static double code(double w0, double M, double D, double h, double l, double d) {
	double tmp;
	if (M <= 3.5e-153) {
		tmp = w0;
	} else {
		tmp = w0 * (1.0 + (-0.125 * (D * ((((M * M) / d) * ((D * h) / d)) / l))));
	}
	return tmp;
}
M = abs(M)
D = abs(D)
[M, D] = sort([M, D])
def code(w0, M, D, h, l, d):
	tmp = 0
	if M <= 3.5e-153:
		tmp = w0
	else:
		tmp = w0 * (1.0 + (-0.125 * (D * ((((M * M) / d) * ((D * h) / d)) / l))))
	return tmp
M = abs(M)
D = abs(D)
M, D = sort([M, D])
function code(w0, M, D, h, l, d)
	tmp = 0.0
	if (M <= 3.5e-153)
		tmp = w0;
	else
		tmp = Float64(w0 * Float64(1.0 + Float64(-0.125 * Float64(D * Float64(Float64(Float64(Float64(M * M) / d) * Float64(Float64(D * h) / d)) / l)))));
	end
	return tmp
end
M = abs(M)
D = abs(D)
M, D = num2cell(sort([M, D])){:}
function tmp_2 = code(w0, M, D, h, l, d)
	tmp = 0.0;
	if (M <= 3.5e-153)
		tmp = w0;
	else
		tmp = w0 * (1.0 + (-0.125 * (D * ((((M * M) / d) * ((D * h) / d)) / l))));
	end
	tmp_2 = tmp;
end
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
code[w0_, M_, D_, h_, l_, d_] := If[LessEqual[M, 3.5e-153], w0, N[(w0 * N[(1.0 + N[(-0.125 * N[(D * N[(N[(N[(N[(M * M), $MachinePrecision] / d), $MachinePrecision] * N[(N[(D * h), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
M = |M|\\
D = |D|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\begin{array}{l}
\mathbf{if}\;M \leq 3.5 \cdot 10^{-153}:\\
\;\;\;\;w0\\

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


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

    1. Initial program 83.4%

      \[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]
    2. Step-by-step derivation
      1. *-commutative83.4%

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

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

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

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

    if 3.49999999999999981e-153 < M

    1. Initial program 80.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto w0 \cdot \color{blue}{\left(1 + \left(\frac{D \cdot D}{d \cdot d} \cdot \frac{\left(M \cdot M\right) \cdot h}{\ell}\right) \cdot -0.125\right)} \]
    7. Taylor expanded in D around 0 46.8%

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

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

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

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

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

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

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

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

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

        \[\leadsto w0 \cdot \left(1 + \left(D \cdot \color{blue}{\left(\left(\frac{h}{d \cdot d} \cdot \left(M \cdot M\right)\right) \cdot \frac{D}{\ell}\right)}\right) \cdot -0.125\right) \]
      10. associate-*r/61.6%

        \[\leadsto w0 \cdot \left(1 + \left(D \cdot \color{blue}{\frac{\left(\frac{h}{d \cdot d} \cdot \left(M \cdot M\right)\right) \cdot D}{\ell}}\right) \cdot -0.125\right) \]
      11. *-commutative61.6%

        \[\leadsto w0 \cdot \left(1 + \left(D \cdot \frac{\color{blue}{\left(\left(M \cdot M\right) \cdot \frac{h}{d \cdot d}\right)} \cdot D}{\ell}\right) \cdot -0.125\right) \]
      12. associate-*l*62.9%

        \[\leadsto w0 \cdot \left(1 + \left(D \cdot \frac{\color{blue}{\left(M \cdot M\right) \cdot \left(\frac{h}{d \cdot d} \cdot D\right)}}{\ell}\right) \cdot -0.125\right) \]
      13. *-commutative62.9%

        \[\leadsto w0 \cdot \left(1 + \left(D \cdot \frac{\left(M \cdot M\right) \cdot \color{blue}{\left(D \cdot \frac{h}{d \cdot d}\right)}}{\ell}\right) \cdot -0.125\right) \]
      14. unpow262.9%

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

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

        \[\leadsto w0 \cdot \left(1 + \left(D \cdot \frac{\left(M \cdot M\right) \cdot \frac{D \cdot h}{\color{blue}{d \cdot d}}}{\ell}\right) \cdot -0.125\right) \]
    9. Simplified62.6%

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

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

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

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

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

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

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

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

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

        \[\leadsto w0 \cdot \left(1 + \left(D \cdot \frac{\frac{\left(M \cdot M\right) \cdot \color{blue}{\left(D \cdot h\right)}}{d \cdot d}}{\ell}\right) \cdot -0.125\right) \]
      9. times-frac67.9%

        \[\leadsto w0 \cdot \left(1 + \left(D \cdot \frac{\color{blue}{\frac{M \cdot M}{d} \cdot \frac{D \cdot h}{d}}}{\ell}\right) \cdot -0.125\right) \]
    12. Simplified67.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;M \leq 3.5 \cdot 10^{-153}:\\ \;\;\;\;w0\\ \mathbf{else}:\\ \;\;\;\;w0 \cdot \left(1 + -0.125 \cdot \left(D \cdot \frac{\frac{M \cdot M}{d} \cdot \frac{D \cdot h}{d}}{\ell}\right)\right)\\ \end{array} \]

Alternative 11: 80.7% accurate, 10.3× speedup?

\[\begin{array}{l} M = |M|\\ D = |D|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ w0 \cdot \left(1 + \left(D \cdot \frac{\frac{D}{\frac{\frac{d}{M} \cdot \frac{d}{M}}{h}}}{\ell}\right) \cdot -0.125\right) \end{array} \]
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
(FPCore (w0 M D h l d)
 :precision binary64
 (* w0 (+ 1.0 (* (* D (/ (/ D (/ (* (/ d M) (/ d M)) h)) l)) -0.125))))
M = abs(M);
D = abs(D);
assert(M < D);
double code(double w0, double M, double D, double h, double l, double d) {
	return w0 * (1.0 + ((D * ((D / (((d / M) * (d / M)) / h)) / l)) * -0.125));
}
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
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 * (1.0d0 + ((d * ((d / (((d_1 / m) * (d_1 / m)) / h)) / l)) * (-0.125d0)))
end function
M = Math.abs(M);
D = Math.abs(D);
assert M < D;
public static double code(double w0, double M, double D, double h, double l, double d) {
	return w0 * (1.0 + ((D * ((D / (((d / M) * (d / M)) / h)) / l)) * -0.125));
}
M = abs(M)
D = abs(D)
[M, D] = sort([M, D])
def code(w0, M, D, h, l, d):
	return w0 * (1.0 + ((D * ((D / (((d / M) * (d / M)) / h)) / l)) * -0.125))
M = abs(M)
D = abs(D)
M, D = sort([M, D])
function code(w0, M, D, h, l, d)
	return Float64(w0 * Float64(1.0 + Float64(Float64(D * Float64(Float64(D / Float64(Float64(Float64(d / M) * Float64(d / M)) / h)) / l)) * -0.125)))
end
M = abs(M)
D = abs(D)
M, D = num2cell(sort([M, D])){:}
function tmp = code(w0, M, D, h, l, d)
	tmp = w0 * (1.0 + ((D * ((D / (((d / M) * (d / M)) / h)) / l)) * -0.125));
end
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
code[w0_, M_, D_, h_, l_, d_] := N[(w0 * N[(1.0 + N[(N[(D * N[(N[(D / N[(N[(N[(d / M), $MachinePrecision] * N[(d / M), $MachinePrecision]), $MachinePrecision] / h), $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision] * -0.125), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
M = |M|\\
D = |D|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
w0 \cdot \left(1 + \left(D \cdot \frac{\frac{D}{\frac{\frac{d}{M} \cdot \frac{d}{M}}{h}}}{\ell}\right) \cdot -0.125\right)
\end{array}
Derivation
  1. Initial program 82.5%

    \[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]
  2. Step-by-step derivation
    1. *-commutative82.5%

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto w0 \cdot \color{blue}{\left(1 + \left(\frac{D \cdot D}{d \cdot d} \cdot \frac{\left(M \cdot M\right) \cdot h}{\ell}\right) \cdot -0.125\right)} \]
  7. Taylor expanded in D around 0 52.5%

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

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

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

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

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

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

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

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

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

      \[\leadsto w0 \cdot \left(1 + \left(D \cdot \color{blue}{\left(\left(\frac{h}{d \cdot d} \cdot \left(M \cdot M\right)\right) \cdot \frac{D}{\ell}\right)}\right) \cdot -0.125\right) \]
    10. associate-*r/66.2%

      \[\leadsto w0 \cdot \left(1 + \left(D \cdot \color{blue}{\frac{\left(\frac{h}{d \cdot d} \cdot \left(M \cdot M\right)\right) \cdot D}{\ell}}\right) \cdot -0.125\right) \]
    11. *-commutative66.2%

      \[\leadsto w0 \cdot \left(1 + \left(D \cdot \frac{\color{blue}{\left(\left(M \cdot M\right) \cdot \frac{h}{d \cdot d}\right)} \cdot D}{\ell}\right) \cdot -0.125\right) \]
    12. associate-*l*66.9%

      \[\leadsto w0 \cdot \left(1 + \left(D \cdot \frac{\color{blue}{\left(M \cdot M\right) \cdot \left(\frac{h}{d \cdot d} \cdot D\right)}}{\ell}\right) \cdot -0.125\right) \]
    13. *-commutative66.9%

      \[\leadsto w0 \cdot \left(1 + \left(D \cdot \frac{\left(M \cdot M\right) \cdot \color{blue}{\left(D \cdot \frac{h}{d \cdot d}\right)}}{\ell}\right) \cdot -0.125\right) \]
    14. unpow266.9%

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

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

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

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

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

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

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

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

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

      \[\leadsto w0 \cdot \left(1 + \left(D \cdot \frac{\frac{D}{\frac{\frac{\color{blue}{d \cdot d}}{M \cdot M}}{h}}}{\ell}\right) \cdot -0.125\right) \]
    6. times-frac77.3%

      \[\leadsto w0 \cdot \left(1 + \left(D \cdot \frac{\frac{D}{\frac{\color{blue}{\frac{d}{M} \cdot \frac{d}{M}}}{h}}}{\ell}\right) \cdot -0.125\right) \]
    7. unpow277.3%

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

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

      \[\leadsto w0 \cdot \left(1 + \left(D \cdot \frac{\frac{D}{\frac{\color{blue}{\frac{d}{M} \cdot \frac{d}{M}}}{h}}}{\ell}\right) \cdot -0.125\right) \]
  14. Applied egg-rr77.3%

    \[\leadsto w0 \cdot \left(1 + \left(D \cdot \frac{\frac{D}{\frac{\color{blue}{\frac{d}{M} \cdot \frac{d}{M}}}{h}}}{\ell}\right) \cdot -0.125\right) \]
  15. Final simplification77.3%

    \[\leadsto w0 \cdot \left(1 + \left(D \cdot \frac{\frac{D}{\frac{\frac{d}{M} \cdot \frac{d}{M}}{h}}}{\ell}\right) \cdot -0.125\right) \]

Alternative 12: 67.7% accurate, 216.0× speedup?

\[\begin{array}{l} M = |M|\\ D = |D|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ w0 \end{array} \]
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
(FPCore (w0 M D h l d) :precision binary64 w0)
M = abs(M);
D = abs(D);
assert(M < D);
double code(double w0, double M, double D, double h, double l, double d) {
	return w0;
}
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
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
end function
M = Math.abs(M);
D = Math.abs(D);
assert M < D;
public static double code(double w0, double M, double D, double h, double l, double d) {
	return w0;
}
M = abs(M)
D = abs(D)
[M, D] = sort([M, D])
def code(w0, M, D, h, l, d):
	return w0
M = abs(M)
D = abs(D)
M, D = sort([M, D])
function code(w0, M, D, h, l, d)
	return w0
end
M = abs(M)
D = abs(D)
M, D = num2cell(sort([M, D])){:}
function tmp = code(w0, M, D, h, l, d)
	tmp = w0;
end
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
code[w0_, M_, D_, h_, l_, d_] := w0
\begin{array}{l}
M = |M|\\
D = |D|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
w0
\end{array}
Derivation
  1. Initial program 82.5%

    \[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]
  2. Step-by-step derivation
    1. *-commutative82.5%

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

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

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

    \[\leadsto \color{blue}{w0} \]
  5. Final simplification70.8%

    \[\leadsto w0 \]

Reproduce

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