Henrywood and Agarwal, Equation (9a)

Percentage Accurate: 80.7% → 88.7%
Time: 16.9s
Alternatives: 8
Speedup: 1.0×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 8 alternatives:

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

Initial Program: 80.7% accurate, 1.0× speedup?

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

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

Alternative 1: 88.7% accurate, 0.3× 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} \cdot \frac{h}{\ell}\\ \mathbf{if}\;t_0 \leq -\infty:\\ \;\;\;\;{\left(\sqrt[3]{w0} \cdot e^{0.16666666666666666 \cdot \left(\log \left(-0.25 \cdot \frac{h \cdot {M}^{2}}{\ell}\right) + \left(-2 \cdot \log d + 2 \cdot \log D\right)\right)}\right)}^{3}\\ \mathbf{elif}\;t_0 \leq 0.5:\\ \;\;\;\;w0 \cdot \sqrt{1 - t_0}\\ \mathbf{else}:\\ \;\;\;\;w0\\ \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) (/ h l))))
   (if (<= t_0 (- INFINITY))
     (pow
      (*
       (cbrt w0)
       (exp
        (*
         0.16666666666666666
         (+
          (log (* -0.25 (/ (* h (pow M 2.0)) l)))
          (+ (* -2.0 (log d)) (* 2.0 (log D)))))))
      3.0)
     (if (<= t_0 0.5) (* w0 (sqrt (- 1.0 t_0))) w0))))
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) * (h / l);
	double tmp;
	if (t_0 <= -((double) INFINITY)) {
		tmp = pow((cbrt(w0) * exp((0.16666666666666666 * (log((-0.25 * ((h * pow(M, 2.0)) / l))) + ((-2.0 * log(d)) + (2.0 * log(D))))))), 3.0);
	} else if (t_0 <= 0.5) {
		tmp = w0 * sqrt((1.0 - t_0));
	} else {
		tmp = w0;
	}
	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) * (h / l);
	double tmp;
	if (t_0 <= -Double.POSITIVE_INFINITY) {
		tmp = Math.pow((Math.cbrt(w0) * Math.exp((0.16666666666666666 * (Math.log((-0.25 * ((h * Math.pow(M, 2.0)) / l))) + ((-2.0 * Math.log(d)) + (2.0 * Math.log(D))))))), 3.0);
	} else if (t_0 <= 0.5) {
		tmp = w0 * Math.sqrt((1.0 - t_0));
	} else {
		tmp = w0;
	}
	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(Float64(M * D) / Float64(2.0 * d)) ^ 2.0) * Float64(h / l))
	tmp = 0.0
	if (t_0 <= Float64(-Inf))
		tmp = Float64(cbrt(w0) * exp(Float64(0.16666666666666666 * Float64(log(Float64(-0.25 * Float64(Float64(h * (M ^ 2.0)) / l))) + Float64(Float64(-2.0 * log(d)) + Float64(2.0 * log(D))))))) ^ 3.0;
	elseif (t_0 <= 0.5)
		tmp = Float64(w0 * sqrt(Float64(1.0 - t_0)));
	else
		tmp = w0;
	end
	return 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[Power[N[(N[(M * D), $MachinePrecision] / N[(2.0 * d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], N[Power[N[(N[Power[w0, 1/3], $MachinePrecision] * N[Exp[N[(0.16666666666666666 * N[(N[Log[N[(-0.25 * N[(N[(h * N[Power[M, 2.0], $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + N[(N[(-2.0 * N[Log[d], $MachinePrecision]), $MachinePrecision] + N[(2.0 * N[Log[D], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 3.0], $MachinePrecision], If[LessEqual[t$95$0, 0.5], N[(w0 * N[Sqrt[N[(1.0 - t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], w0]]]
\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} \cdot \frac{h}{\ell}\\
\mathbf{if}\;t_0 \leq -\infty:\\
\;\;\;\;{\left(\sqrt[3]{w0} \cdot e^{0.16666666666666666 \cdot \left(\log \left(-0.25 \cdot \frac{h \cdot {M}^{2}}{\ell}\right) + \left(-2 \cdot \log d + 2 \cdot \log D\right)\right)}\right)}^{3}\\

\mathbf{elif}\;t_0 \leq 0.5:\\
\;\;\;\;w0 \cdot \sqrt{1 - t_0}\\

\mathbf{else}:\\
\;\;\;\;w0\\


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

    1. Initial program 57.3%

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

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

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

      \[\leadsto {\color{blue}{\left({\left(1 \cdot w0\right)}^{0.3333333333333333} \cdot e^{0.16666666666666666 \cdot \left(\log \left(-0.25 \cdot \frac{{D}^{2} \cdot \left({M}^{2} \cdot h\right)}{\ell}\right) + -2 \cdot \log d\right)}\right)}}^{3} \]
    5. Step-by-step derivation
      1. unpow1/335.0%

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

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

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

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

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

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

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

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

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

    if -inf.0 < (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 2 d)) 2) (/.f64 h l)) < 0.5

    1. Initial program 99.9%

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

    if 0.5 < (*.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. Simplified0.0%

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

      \[\leadsto \color{blue}{w0} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification78.0%

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

Alternative 2: 88.9% accurate, 0.3× 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} \cdot \frac{h}{\ell}\\ \mathbf{if}\;t_0 \leq -\infty:\\ \;\;\;\;{\left(\sqrt[3]{w0} \cdot e^{0.16666666666666666 \cdot \left(-2 \cdot \log d + \log \left(\frac{h \cdot {\left(M \cdot D\right)}^{2}}{\ell} \cdot \left(-0.25\right)\right)\right)}\right)}^{3}\\ \mathbf{elif}\;t_0 \leq 0.5:\\ \;\;\;\;w0 \cdot \sqrt{1 - t_0}\\ \mathbf{else}:\\ \;\;\;\;w0\\ \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) (/ h l))))
   (if (<= t_0 (- INFINITY))
     (pow
      (*
       (cbrt w0)
       (exp
        (*
         0.16666666666666666
         (+
          (* -2.0 (log d))
          (log (* (/ (* h (pow (* M D) 2.0)) l) (- 0.25)))))))
      3.0)
     (if (<= t_0 0.5) (* w0 (sqrt (- 1.0 t_0))) w0))))
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) * (h / l);
	double tmp;
	if (t_0 <= -((double) INFINITY)) {
		tmp = pow((cbrt(w0) * exp((0.16666666666666666 * ((-2.0 * log(d)) + log((((h * pow((M * D), 2.0)) / l) * -0.25)))))), 3.0);
	} else if (t_0 <= 0.5) {
		tmp = w0 * sqrt((1.0 - t_0));
	} else {
		tmp = w0;
	}
	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) * (h / l);
	double tmp;
	if (t_0 <= -Double.POSITIVE_INFINITY) {
		tmp = Math.pow((Math.cbrt(w0) * Math.exp((0.16666666666666666 * ((-2.0 * Math.log(d)) + Math.log((((h * Math.pow((M * D), 2.0)) / l) * -0.25)))))), 3.0);
	} else if (t_0 <= 0.5) {
		tmp = w0 * Math.sqrt((1.0 - t_0));
	} else {
		tmp = w0;
	}
	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(Float64(M * D) / Float64(2.0 * d)) ^ 2.0) * Float64(h / l))
	tmp = 0.0
	if (t_0 <= Float64(-Inf))
		tmp = Float64(cbrt(w0) * exp(Float64(0.16666666666666666 * Float64(Float64(-2.0 * log(d)) + log(Float64(Float64(Float64(h * (Float64(M * D) ^ 2.0)) / l) * Float64(-0.25))))))) ^ 3.0;
	elseif (t_0 <= 0.5)
		tmp = Float64(w0 * sqrt(Float64(1.0 - t_0)));
	else
		tmp = w0;
	end
	return 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[Power[N[(N[(M * D), $MachinePrecision] / N[(2.0 * d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], N[Power[N[(N[Power[w0, 1/3], $MachinePrecision] * N[Exp[N[(0.16666666666666666 * N[(N[(-2.0 * N[Log[d], $MachinePrecision]), $MachinePrecision] + N[Log[N[(N[(N[(h * N[Power[N[(M * D), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision] * (-0.25)), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 3.0], $MachinePrecision], If[LessEqual[t$95$0, 0.5], N[(w0 * N[Sqrt[N[(1.0 - t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], w0]]]
\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} \cdot \frac{h}{\ell}\\
\mathbf{if}\;t_0 \leq -\infty:\\
\;\;\;\;{\left(\sqrt[3]{w0} \cdot e^{0.16666666666666666 \cdot \left(-2 \cdot \log d + \log \left(\frac{h \cdot {\left(M \cdot D\right)}^{2}}{\ell} \cdot \left(-0.25\right)\right)\right)}\right)}^{3}\\

\mathbf{elif}\;t_0 \leq 0.5:\\
\;\;\;\;w0 \cdot \sqrt{1 - t_0}\\

\mathbf{else}:\\
\;\;\;\;w0\\


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

    1. Initial program 57.3%

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

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

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

      \[\leadsto {\color{blue}{\left({\left(1 \cdot w0\right)}^{0.3333333333333333} \cdot e^{0.16666666666666666 \cdot \left(\log \left(-0.25 \cdot \frac{{D}^{2} \cdot \left({M}^{2} \cdot h\right)}{\ell}\right) + -2 \cdot \log d\right)}\right)}}^{3} \]
    5. Step-by-step derivation
      1. expm1-log1p-u11.5%

        \[\leadsto {\left({\left(1 \cdot w0\right)}^{0.3333333333333333} \cdot e^{0.16666666666666666 \cdot \left(\log \left(-0.25 \cdot \frac{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left({D}^{2} \cdot \left({M}^{2} \cdot h\right)\right)\right)}}{\ell}\right) + -2 \cdot \log d\right)}\right)}^{3} \]
      2. expm1-udef9.9%

        \[\leadsto {\left({\left(1 \cdot w0\right)}^{0.3333333333333333} \cdot e^{0.16666666666666666 \cdot \left(\log \left(-0.25 \cdot \frac{\color{blue}{e^{\mathsf{log1p}\left({D}^{2} \cdot \left({M}^{2} \cdot h\right)\right)} - 1}}{\ell}\right) + -2 \cdot \log d\right)}\right)}^{3} \]
      3. associate-*r*9.9%

        \[\leadsto {\left({\left(1 \cdot w0\right)}^{0.3333333333333333} \cdot e^{0.16666666666666666 \cdot \left(\log \left(-0.25 \cdot \frac{e^{\mathsf{log1p}\left(\color{blue}{\left({D}^{2} \cdot {M}^{2}\right) \cdot h}\right)} - 1}{\ell}\right) + -2 \cdot \log d\right)}\right)}^{3} \]
      4. pow-prod-down9.9%

        \[\leadsto {\left({\left(1 \cdot w0\right)}^{0.3333333333333333} \cdot e^{0.16666666666666666 \cdot \left(\log \left(-0.25 \cdot \frac{e^{\mathsf{log1p}\left(\color{blue}{{\left(D \cdot M\right)}^{2}} \cdot h\right)} - 1}{\ell}\right) + -2 \cdot \log d\right)}\right)}^{3} \]
    6. Applied egg-rr9.9%

      \[\leadsto {\left({\left(1 \cdot w0\right)}^{0.3333333333333333} \cdot e^{0.16666666666666666 \cdot \left(\log \left(-0.25 \cdot \frac{\color{blue}{e^{\mathsf{log1p}\left({\left(D \cdot M\right)}^{2} \cdot h\right)} - 1}}{\ell}\right) + -2 \cdot \log d\right)}\right)}^{3} \]
    7. Step-by-step derivation
      1. expm1-def11.9%

        \[\leadsto {\left({\left(1 \cdot w0\right)}^{0.3333333333333333} \cdot e^{0.16666666666666666 \cdot \left(\log \left(-0.25 \cdot \frac{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left({\left(D \cdot M\right)}^{2} \cdot h\right)\right)}}{\ell}\right) + -2 \cdot \log d\right)}\right)}^{3} \]
      2. expm1-log1p25.2%

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

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

      \[\leadsto {\left({\left(1 \cdot w0\right)}^{0.3333333333333333} \cdot e^{0.16666666666666666 \cdot \left(\log \left(-0.25 \cdot \frac{\color{blue}{h \cdot {\left(D \cdot M\right)}^{2}}}{\ell}\right) + -2 \cdot \log d\right)}\right)}^{3} \]
    9. Step-by-step derivation
      1. expm1-log1p-u25.2%

        \[\leadsto {\left(\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left({\left(1 \cdot w0\right)}^{0.3333333333333333}\right)\right)} \cdot e^{0.16666666666666666 \cdot \left(\log \left(-0.25 \cdot \frac{h \cdot {\left(D \cdot M\right)}^{2}}{\ell}\right) + -2 \cdot \log d\right)}\right)}^{3} \]
      2. expm1-udef20.3%

        \[\leadsto {\left(\color{blue}{\left(e^{\mathsf{log1p}\left({\left(1 \cdot w0\right)}^{0.3333333333333333}\right)} - 1\right)} \cdot e^{0.16666666666666666 \cdot \left(\log \left(-0.25 \cdot \frac{h \cdot {\left(D \cdot M\right)}^{2}}{\ell}\right) + -2 \cdot \log d\right)}\right)}^{3} \]
      3. unpow1/320.5%

        \[\leadsto {\left(\left(e^{\mathsf{log1p}\left(\color{blue}{\sqrt[3]{1 \cdot w0}}\right)} - 1\right) \cdot e^{0.16666666666666666 \cdot \left(\log \left(-0.25 \cdot \frac{h \cdot {\left(D \cdot M\right)}^{2}}{\ell}\right) + -2 \cdot \log d\right)}\right)}^{3} \]
      4. *-un-lft-identity20.5%

        \[\leadsto {\left(\left(e^{\mathsf{log1p}\left(\sqrt[3]{\color{blue}{w0}}\right)} - 1\right) \cdot e^{0.16666666666666666 \cdot \left(\log \left(-0.25 \cdot \frac{h \cdot {\left(D \cdot M\right)}^{2}}{\ell}\right) + -2 \cdot \log d\right)}\right)}^{3} \]
    10. Applied egg-rr20.5%

      \[\leadsto {\left(\color{blue}{\left(e^{\mathsf{log1p}\left(\sqrt[3]{w0}\right)} - 1\right)} \cdot e^{0.16666666666666666 \cdot \left(\log \left(-0.25 \cdot \frac{h \cdot {\left(D \cdot M\right)}^{2}}{\ell}\right) + -2 \cdot \log d\right)}\right)}^{3} \]
    11. Step-by-step derivation
      1. expm1-def26.8%

        \[\leadsto {\left(\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt[3]{w0}\right)\right)} \cdot e^{0.16666666666666666 \cdot \left(\log \left(-0.25 \cdot \frac{h \cdot {\left(D \cdot M\right)}^{2}}{\ell}\right) + -2 \cdot \log d\right)}\right)}^{3} \]
      2. expm1-log1p38.4%

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

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

    if -inf.0 < (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 2 d)) 2) (/.f64 h l)) < 0.5

    1. Initial program 99.9%

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

    if 0.5 < (*.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. Simplified0.0%

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

      \[\leadsto \color{blue}{w0} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification83.5%

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

Alternative 3: 86.3% 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} \cdot \frac{h}{\ell}\\ \mathbf{if}\;t_0 \leq 0.5:\\ \;\;\;\;w0 \cdot \sqrt{1 - t_0}\\ \mathbf{else}:\\ \;\;\;\;w0\\ \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) (/ h l))))
   (if (<= t_0 0.5) (* w0 (sqrt (- 1.0 t_0))) w0)))
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) * (h / l);
	double tmp;
	if (t_0 <= 0.5) {
		tmp = w0 * sqrt((1.0 - t_0));
	} else {
		tmp = w0;
	}
	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 = (((m * d) / (2.0d0 * d_1)) ** 2.0d0) * (h / l)
    if (t_0 <= 0.5d0) then
        tmp = w0 * sqrt((1.0d0 - t_0))
    else
        tmp = w0
    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 = Math.pow(((M * D) / (2.0 * d)), 2.0) * (h / l);
	double tmp;
	if (t_0 <= 0.5) {
		tmp = w0 * Math.sqrt((1.0 - t_0));
	} else {
		tmp = w0;
	}
	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) * (h / l)
	tmp = 0
	if t_0 <= 0.5:
		tmp = w0 * math.sqrt((1.0 - t_0))
	else:
		tmp = w0
	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(Float64(M * D) / Float64(2.0 * d)) ^ 2.0) * Float64(h / l))
	tmp = 0.0
	if (t_0 <= 0.5)
		tmp = Float64(w0 * sqrt(Float64(1.0 - t_0)));
	else
		tmp = w0;
	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) * (h / l);
	tmp = 0.0;
	if (t_0 <= 0.5)
		tmp = w0 * sqrt((1.0 - t_0));
	else
		tmp = w0;
	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[Power[N[(N[(M * D), $MachinePrecision] / N[(2.0 * d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 0.5], N[(w0 * N[Sqrt[N[(1.0 - t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], w0]]
\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} \cdot \frac{h}{\ell}\\
\mathbf{if}\;t_0 \leq 0.5:\\
\;\;\;\;w0 \cdot \sqrt{1 - t_0}\\

\mathbf{else}:\\
\;\;\;\;w0\\


\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)) < 0.5

    1. Initial program 89.1%

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

    if 0.5 < (*.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. Simplified0.0%

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

      \[\leadsto \color{blue}{w0} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification87.9%

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

Alternative 4: 85.9% accurate, 1.0× speedup?

\[\begin{array}{l} M = |M|\\ d = |d|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ \begin{array}{l} \mathbf{if}\;\frac{h}{\ell} \leq -2 \cdot 10^{+288}:\\ \;\;\;\;w0 \cdot \mathsf{fma}\left(-0.125, h \cdot \frac{{\left(M \cdot \frac{D}{d}\right)}^{2}}{\ell}, 1\right)\\ \mathbf{elif}\;\frac{h}{\ell} \leq -1 \cdot 10^{-281}:\\ \;\;\;\;w0 \cdot \sqrt{1 - \frac{h}{\ell} \cdot {\left(\frac{D}{2} \cdot \frac{M}{d}\right)}^{2}}\\ \mathbf{else}:\\ \;\;\;\;w0\\ \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 l) -2e+288)
   (* w0 (fma -0.125 (* h (/ (pow (* M (/ D d)) 2.0) l)) 1.0))
   (if (<= (/ h l) -1e-281)
     (* w0 (sqrt (- 1.0 (* (/ h l) (pow (* (/ D 2.0) (/ M d)) 2.0)))))
     w0)))
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 / l) <= -2e+288) {
		tmp = w0 * fma(-0.125, (h * (pow((M * (D / d)), 2.0) / l)), 1.0);
	} else if ((h / l) <= -1e-281) {
		tmp = w0 * sqrt((1.0 - ((h / l) * pow(((D / 2.0) * (M / d)), 2.0))));
	} else {
		tmp = w0;
	}
	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(h / l) <= -2e+288)
		tmp = Float64(w0 * fma(-0.125, Float64(h * Float64((Float64(M * Float64(D / d)) ^ 2.0) / l)), 1.0));
	elseif (Float64(h / l) <= -1e-281)
		tmp = Float64(w0 * sqrt(Float64(1.0 - Float64(Float64(h / l) * (Float64(Float64(D / 2.0) * Float64(M / d)) ^ 2.0)))));
	else
		tmp = w0;
	end
	return 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[(h / l), $MachinePrecision], -2e+288], N[(w0 * N[(-0.125 * N[(h * N[(N[Power[N[(M * N[(D / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(h / l), $MachinePrecision], -1e-281], 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], w0]]
\begin{array}{l}
M = |M|\\
d = |d|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\begin{array}{l}
\mathbf{if}\;\frac{h}{\ell} \leq -2 \cdot 10^{+288}:\\
\;\;\;\;w0 \cdot \mathsf{fma}\left(-0.125, h \cdot \frac{{\left(M \cdot \frac{D}{d}\right)}^{2}}{\ell}, 1\right)\\

\mathbf{elif}\;\frac{h}{\ell} \leq -1 \cdot 10^{-281}:\\
\;\;\;\;w0 \cdot \sqrt{1 - \frac{h}{\ell} \cdot {\left(\frac{D}{2} \cdot \frac{M}{d}\right)}^{2}}\\

\mathbf{else}:\\
\;\;\;\;w0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (/.f64 h l) < -2e288

    1. Initial program 42.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto w0 \cdot \mathsf{fma}\left(-0.125, \frac{\color{blue}{{\left(\frac{D}{d} \cdot M\right)}^{2}}}{\frac{\ell}{h}}, 1\right) \]
      12. associate-*l/42.2%

        \[\leadsto w0 \cdot \mathsf{fma}\left(-0.125, \frac{{\color{blue}{\left(\frac{D \cdot M}{d}\right)}}^{2}}{\frac{\ell}{h}}, 1\right) \]
      13. associate-/l*42.2%

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

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

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

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

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

    if -2e288 < (/.f64 h l) < -1e-281

    1. Initial program 86.1%

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

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

    if -1e-281 < (/.f64 h l)

    1. Initial program 88.9%

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

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

      \[\leadsto \color{blue}{w0} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification85.9%

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

Alternative 5: 85.7% accurate, 1.0× speedup?

\[\begin{array}{l} M = |M|\\ d = |d|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ w0 \cdot \sqrt{1 - \frac{h \cdot {\left(0.5 \cdot \frac{M \cdot D}{d}\right)}^{2}}{\ell}} \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 (sqrt (- 1.0 (/ (* h (pow (* 0.5 (/ (* M D) d)) 2.0)) l)))))
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 * sqrt((1.0 - ((h * pow((0.5 * ((M * D) / d)), 2.0)) / l)));
}
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 * sqrt((1.0d0 - ((h * ((0.5d0 * ((m * d) / d_1)) ** 2.0d0)) / l)))
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 * Math.sqrt((1.0 - ((h * Math.pow((0.5 * ((M * D) / d)), 2.0)) / l)));
}
M = abs(M)
d = abs(d)
[M, D] = sort([M, D])
def code(w0, M, D, h, l, d):
	return w0 * math.sqrt((1.0 - ((h * math.pow((0.5 * ((M * D) / d)), 2.0)) / l)))
M = abs(M)
d = abs(d)
M, D = sort([M, D])
function code(w0, M, D, h, l, d)
	return Float64(w0 * sqrt(Float64(1.0 - Float64(Float64(h * (Float64(0.5 * Float64(Float64(M * D) / d)) ^ 2.0)) / l))))
end
M = abs(M)
d = abs(d)
M, D = num2cell(sort([M, D])){:}
function tmp = code(w0, M, D, h, l, d)
	tmp = w0 * sqrt((1.0 - ((h * ((0.5 * ((M * D) / d)) ^ 2.0)) / l)));
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[Sqrt[N[(1.0 - N[(N[(h * N[Power[N[(0.5 * N[(N[(M * D), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
M = |M|\\
d = |d|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
w0 \cdot \sqrt{1 - \frac{h \cdot {\left(0.5 \cdot \frac{M \cdot D}{d}\right)}^{2}}{\ell}}
\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. Simplified81.3%

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

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

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

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

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

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

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

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

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

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

Alternative 6: 80.2% accurate, 1.0× speedup?

\[\begin{array}{l} M = |M|\\ d = |d|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ w0 \cdot \mathsf{fma}\left(-0.125, h \cdot \frac{{\left(M \cdot \frac{D}{d}\right)}^{2}}{\ell}, 1\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 (fma -0.125 (* h (/ (pow (* M (/ D d)) 2.0) l)) 1.0)))
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 * fma(-0.125, (h * (pow((M * (D / d)), 2.0) / l)), 1.0);
}
M = abs(M)
d = abs(d)
M, D = sort([M, D])
function code(w0, M, D, h, l, d)
	return Float64(w0 * fma(-0.125, Float64(h * Float64((Float64(M * Float64(D / d)) ^ 2.0) / l)), 1.0))
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[(-0.125 * N[(h * N[(N[Power[N[(M * N[(D / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
M = |M|\\
d = |d|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
w0 \cdot \mathsf{fma}\left(-0.125, h \cdot \frac{{\left(M \cdot \frac{D}{d}\right)}^{2}}{\ell}, 1\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. Simplified81.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto w0 \cdot \mathsf{fma}\left(-0.125, \frac{\color{blue}{{\left(\frac{D}{d} \cdot M\right)}^{2}}}{\frac{\ell}{h}}, 1\right) \]
    12. associate-*l/75.8%

      \[\leadsto w0 \cdot \mathsf{fma}\left(-0.125, \frac{{\color{blue}{\left(\frac{D \cdot M}{d}\right)}}^{2}}{\frac{\ell}{h}}, 1\right) \]
    13. associate-/l*75.4%

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

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

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

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

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

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

Alternative 7: 76.1% accurate, 1.8× speedup?

\[\begin{array}{l} M = |M|\\ d = |d|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ \begin{array}{l} t_0 := M \cdot \frac{D}{d}\\ \mathbf{if}\;D \leq 1.55 \cdot 10^{+113}:\\ \;\;\;\;w0\\ \mathbf{else}:\\ \;\;\;\;w0 \cdot \mathsf{fma}\left(-0.125, \frac{t_0 \cdot t_0}{\frac{\ell}{h}}, 1\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 (* M (/ D d))))
   (if (<= D 1.55e+113) w0 (* w0 (fma -0.125 (/ (* t_0 t_0) (/ l h)) 1.0)))))
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 = M * (D / d);
	double tmp;
	if (D <= 1.55e+113) {
		tmp = w0;
	} else {
		tmp = w0 * fma(-0.125, ((t_0 * t_0) / (l / h)), 1.0);
	}
	return tmp;
}
M = abs(M)
d = abs(d)
M, D = sort([M, D])
function code(w0, M, D, h, l, d)
	t_0 = Float64(M * Float64(D / d))
	tmp = 0.0
	if (D <= 1.55e+113)
		tmp = w0;
	else
		tmp = Float64(w0 * fma(-0.125, Float64(Float64(t_0 * t_0) / Float64(l / h)), 1.0));
	end
	return 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[(M * N[(D / d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[D, 1.55e+113], w0, N[(w0 * N[(-0.125 * N[(N[(t$95$0 * t$95$0), $MachinePrecision] / N[(l / h), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
M = |M|\\
d = |d|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\begin{array}{l}
t_0 := M \cdot \frac{D}{d}\\
\mathbf{if}\;D \leq 1.55 \cdot 10^{+113}:\\
\;\;\;\;w0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if D < 1.54999999999999996e113

    1. Initial program 84.0%

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

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

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

    if 1.54999999999999996e113 < D

    1. Initial program 74.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto w0 \cdot \mathsf{fma}\left(-0.125, \frac{\color{blue}{{\left(\frac{D}{d} \cdot M\right)}^{2}}}{\frac{\ell}{h}}, 1\right) \]
      12. associate-*l/61.7%

        \[\leadsto w0 \cdot \mathsf{fma}\left(-0.125, \frac{{\color{blue}{\left(\frac{D \cdot M}{d}\right)}}^{2}}{\frac{\ell}{h}}, 1\right) \]
      13. associate-/l*61.7%

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

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

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

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

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

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

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

Alternative 8: 68.2% 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. Simplified81.3%

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

    \[\leadsto \color{blue}{w0} \]
  4. Final simplification67.7%

    \[\leadsto w0 \]

Reproduce

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