Henrywood and Agarwal, Equation (9a)

Percentage Accurate: 80.8% → 86.1%
Time: 16.0s
Alternatives: 12
Speedup: 10.3×

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: 80.8% 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: 86.1% 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^{-30}:\\ \;\;\;\;w0 \cdot \sqrt{1 + \frac{-1}{\frac{\ell}{h \cdot {\left(\frac{M}{d} \cdot \left(D \cdot 0.5\right)\right)}^{2}}}}\\ \mathbf{else}:\\ \;\;\;\;w0 \cdot \left(1 + \frac{D \cdot \left(D \cdot \left(\frac{M}{d} \cdot \frac{h \cdot M}{d}\right)\right)}{\ell} \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 l) -2e-30)
   (* w0 (sqrt (+ 1.0 (/ -1.0 (/ l (* h (pow (* (/ M d) (* D 0.5)) 2.0)))))))
   (* w0 (+ 1.0 (* (/ (* D (* D (* (/ M d) (/ (* h M) d)))) 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 / l) <= -2e-30) {
		tmp = w0 * sqrt((1.0 + (-1.0 / (l / (h * pow(((M / d) * (D * 0.5)), 2.0))))));
	} else {
		tmp = w0 * (1.0 + (((D * (D * ((M / d) * ((h * M) / d)))) / 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 / l) <= (-2d-30)) then
        tmp = w0 * sqrt((1.0d0 + ((-1.0d0) / (l / (h * (((m / d_1) * (d * 0.5d0)) ** 2.0d0))))))
    else
        tmp = w0 * (1.0d0 + (((d * (d * ((m / d_1) * ((h * m) / d_1)))) / 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 / l) <= -2e-30) {
		tmp = w0 * Math.sqrt((1.0 + (-1.0 / (l / (h * Math.pow(((M / d) * (D * 0.5)), 2.0))))));
	} else {
		tmp = w0 * (1.0 + (((D * (D * ((M / d) * ((h * M) / d)))) / 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 / l) <= -2e-30:
		tmp = w0 * math.sqrt((1.0 + (-1.0 / (l / (h * math.pow(((M / d) * (D * 0.5)), 2.0))))))
	else:
		tmp = w0 * (1.0 + (((D * (D * ((M / d) * ((h * M) / d)))) / 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(h / l) <= -2e-30)
		tmp = Float64(w0 * sqrt(Float64(1.0 + Float64(-1.0 / Float64(l / Float64(h * (Float64(Float64(M / d) * Float64(D * 0.5)) ^ 2.0)))))));
	else
		tmp = Float64(w0 * Float64(1.0 + Float64(Float64(Float64(D * Float64(D * Float64(Float64(M / d) * Float64(Float64(h * M) / d)))) / 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 / l) <= -2e-30)
		tmp = w0 * sqrt((1.0 + (-1.0 / (l / (h * (((M / d) * (D * 0.5)) ^ 2.0))))));
	else
		tmp = w0 * (1.0 + (((D * (D * ((M / d) * ((h * M) / d)))) / 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[(h / l), $MachinePrecision], -2e-30], N[(w0 * N[Sqrt[N[(1.0 + N[(-1.0 / N[(l / N[(h * N[Power[N[(N[(M / d), $MachinePrecision] * N[(D * 0.5), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(w0 * N[(1.0 + N[(N[(N[(D * N[(D * N[(N[(M / d), $MachinePrecision] * N[(N[(h * M), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision] * -0.125), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\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^{-30}:\\
\;\;\;\;w0 \cdot \sqrt{1 + \frac{-1}{\frac{\ell}{h \cdot {\left(\frac{M}{d} \cdot \left(D \cdot 0.5\right)\right)}^{2}}}}\\

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


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

    1. Initial program 75.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. times-frac75.0%

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

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

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

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

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

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

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

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

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

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

    if -2e-30 < (/.f64 h l)

    1. Initial program 88.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. times-frac88.3%

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

      \[\leadsto \color{blue}{w0 \cdot \sqrt{1 - {\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}}} \]
    4. Taylor expanded in M around 0 58.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. associate-*r/58.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 87.4% accurate, 0.7× speedup?

\[\begin{array}{l} M = |M|\\ D = |D|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ \begin{array}{l} \mathbf{if}\;\frac{h}{\ell} \cdot {\left(\frac{M \cdot D}{d \cdot 2}\right)}^{2} \leq 5 \cdot 10^{-28}:\\ \;\;\;\;w0 \cdot \sqrt{1 - \frac{h}{\ell} \cdot {\left(\frac{M}{d} \cdot \frac{D}{2}\right)}^{2}}\\ \mathbf{else}:\\ \;\;\;\;w0 \cdot \sqrt{1 - \frac{D}{d} \cdot \left(\frac{D}{\frac{\ell}{M \cdot \left(h \cdot M\right)}} \cdot \frac{0.25}{d}\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 l) (pow (/ (* M D) (* d 2.0)) 2.0)) 5e-28)
   (* w0 (sqrt (- 1.0 (* (/ h l) (pow (* (/ M d) (/ D 2.0)) 2.0)))))
   (* w0 (sqrt (- 1.0 (* (/ D d) (* (/ D (/ l (* M (* h M)))) (/ 0.25 d))))))))
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) * pow(((M * D) / (d * 2.0)), 2.0)) <= 5e-28) {
		tmp = w0 * sqrt((1.0 - ((h / l) * pow(((M / d) * (D / 2.0)), 2.0))));
	} else {
		tmp = w0 * sqrt((1.0 - ((D / d) * ((D / (l / (M * (h * M)))) * (0.25 / d)))));
	}
	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 / l) * (((m * d) / (d_1 * 2.0d0)) ** 2.0d0)) <= 5d-28) then
        tmp = w0 * sqrt((1.0d0 - ((h / l) * (((m / d_1) * (d / 2.0d0)) ** 2.0d0))))
    else
        tmp = w0 * sqrt((1.0d0 - ((d / d_1) * ((d / (l / (m * (h * m)))) * (0.25d0 / d_1)))))
    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 / l) * Math.pow(((M * D) / (d * 2.0)), 2.0)) <= 5e-28) {
		tmp = w0 * Math.sqrt((1.0 - ((h / l) * Math.pow(((M / d) * (D / 2.0)), 2.0))));
	} else {
		tmp = w0 * Math.sqrt((1.0 - ((D / d) * ((D / (l / (M * (h * M)))) * (0.25 / d)))));
	}
	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 / l) * math.pow(((M * D) / (d * 2.0)), 2.0)) <= 5e-28:
		tmp = w0 * math.sqrt((1.0 - ((h / l) * math.pow(((M / d) * (D / 2.0)), 2.0))))
	else:
		tmp = w0 * math.sqrt((1.0 - ((D / d) * ((D / (l / (M * (h * M)))) * (0.25 / d)))))
	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(h / l) * (Float64(Float64(M * D) / Float64(d * 2.0)) ^ 2.0)) <= 5e-28)
		tmp = Float64(w0 * sqrt(Float64(1.0 - Float64(Float64(h / l) * (Float64(Float64(M / d) * Float64(D / 2.0)) ^ 2.0)))));
	else
		tmp = Float64(w0 * sqrt(Float64(1.0 - Float64(Float64(D / d) * Float64(Float64(D / Float64(l / Float64(M * Float64(h * M)))) * Float64(0.25 / d))))));
	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 / l) * (((M * D) / (d * 2.0)) ^ 2.0)) <= 5e-28)
		tmp = w0 * sqrt((1.0 - ((h / l) * (((M / d) * (D / 2.0)) ^ 2.0))));
	else
		tmp = w0 * sqrt((1.0 - ((D / d) * ((D / (l / (M * (h * M)))) * (0.25 / d)))));
	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[(h / l), $MachinePrecision] * N[Power[N[(N[(M * D), $MachinePrecision] / N[(d * 2.0), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision], 5e-28], N[(w0 * N[Sqrt[N[(1.0 - N[(N[(h / l), $MachinePrecision] * N[Power[N[(N[(M / d), $MachinePrecision] * N[(D / 2.0), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(w0 * N[Sqrt[N[(1.0 - N[(N[(D / d), $MachinePrecision] * N[(N[(D / N[(l / N[(M * N[(h * M), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(0.25 / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
M = |M|\\
D = |D|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\begin{array}{l}
\mathbf{if}\;\frac{h}{\ell} \cdot {\left(\frac{M \cdot D}{d \cdot 2}\right)}^{2} \leq 5 \cdot 10^{-28}:\\
\;\;\;\;w0 \cdot \sqrt{1 - \frac{h}{\ell} \cdot {\left(\frac{M}{d} \cdot \frac{D}{2}\right)}^{2}}\\

\mathbf{else}:\\
\;\;\;\;w0 \cdot \sqrt{1 - \frac{D}{d} \cdot \left(\frac{D}{\frac{\ell}{M \cdot \left(h \cdot M\right)}} \cdot \frac{0.25}{d}\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)) < 5.0000000000000002e-28

    1. Initial program 89.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. *-commutative89.4%

        \[\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 5.0000000000000002e-28 < (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 2 d)) 2) (/.f64 h l))

    1. Initial program 10.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. times-frac14.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\frac{0.25}{d} \cdot \frac{D \cdot \left(D \cdot \left(M \cdot \left(M \cdot h\right)\right)\right)}{d \cdot \ell}}} \]
    12. Step-by-step derivation
      1. *-un-lft-identity60.7%

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

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

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

      \[\leadsto w0 \cdot \color{blue}{\left(1 \cdot \sqrt{1 - \left(\frac{D}{d} \cdot \frac{D \cdot \left(M \cdot \left(M \cdot h\right)\right)}{\ell}\right) \cdot \frac{0.25}{d}}\right)} \]
    14. Step-by-step derivation
      1. *-lft-identity60.6%

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

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

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

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

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

Alternative 3: 86.3% 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 -\infty:\\ \;\;\;\;w0 \cdot \sqrt{1 - \frac{D}{d} \cdot \left(\frac{D}{\frac{\ell}{M \cdot \left(h \cdot M\right)}} \cdot \frac{0.25}{d}\right)}\\ \mathbf{elif}\;\frac{h}{\ell} \leq -2 \cdot 10^{-30}:\\ \;\;\;\;w0 \cdot \sqrt{1 - \frac{h}{\ell} \cdot {\left(\frac{D}{d} \cdot \frac{M}{2}\right)}^{2}}\\ \mathbf{else}:\\ \;\;\;\;w0 \cdot \left(1 + \frac{D \cdot \left(D \cdot \left(\frac{M}{d} \cdot \frac{h \cdot M}{d}\right)\right)}{\ell} \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 l) (- INFINITY))
   (* w0 (sqrt (- 1.0 (* (/ D d) (* (/ D (/ l (* M (* h M)))) (/ 0.25 d))))))
   (if (<= (/ h l) -2e-30)
     (* w0 (sqrt (- 1.0 (* (/ h l) (pow (* (/ D d) (/ M 2.0)) 2.0)))))
     (* w0 (+ 1.0 (* (/ (* D (* D (* (/ M d) (/ (* h M) d)))) 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 / l) <= -((double) INFINITY)) {
		tmp = w0 * sqrt((1.0 - ((D / d) * ((D / (l / (M * (h * M)))) * (0.25 / d)))));
	} else if ((h / l) <= -2e-30) {
		tmp = w0 * sqrt((1.0 - ((h / l) * pow(((D / d) * (M / 2.0)), 2.0))));
	} else {
		tmp = w0 * (1.0 + (((D * (D * ((M / d) * ((h * M) / d)))) / l) * -0.125));
	}
	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 tmp;
	if ((h / l) <= -Double.POSITIVE_INFINITY) {
		tmp = w0 * Math.sqrt((1.0 - ((D / d) * ((D / (l / (M * (h * M)))) * (0.25 / d)))));
	} else if ((h / l) <= -2e-30) {
		tmp = w0 * Math.sqrt((1.0 - ((h / l) * Math.pow(((D / d) * (M / 2.0)), 2.0))));
	} else {
		tmp = w0 * (1.0 + (((D * (D * ((M / d) * ((h * M) / d)))) / 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 / l) <= -math.inf:
		tmp = w0 * math.sqrt((1.0 - ((D / d) * ((D / (l / (M * (h * M)))) * (0.25 / d)))))
	elif (h / l) <= -2e-30:
		tmp = w0 * math.sqrt((1.0 - ((h / l) * math.pow(((D / d) * (M / 2.0)), 2.0))))
	else:
		tmp = w0 * (1.0 + (((D * (D * ((M / d) * ((h * M) / d)))) / 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(h / l) <= Float64(-Inf))
		tmp = Float64(w0 * sqrt(Float64(1.0 - Float64(Float64(D / d) * Float64(Float64(D / Float64(l / Float64(M * Float64(h * M)))) * Float64(0.25 / d))))));
	elseif (Float64(h / l) <= -2e-30)
		tmp = Float64(w0 * sqrt(Float64(1.0 - Float64(Float64(h / l) * (Float64(Float64(D / d) * Float64(M / 2.0)) ^ 2.0)))));
	else
		tmp = Float64(w0 * Float64(1.0 + Float64(Float64(Float64(D * Float64(D * Float64(Float64(M / d) * Float64(Float64(h * M) / d)))) / 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 / l) <= -Inf)
		tmp = w0 * sqrt((1.0 - ((D / d) * ((D / (l / (M * (h * M)))) * (0.25 / d)))));
	elseif ((h / l) <= -2e-30)
		tmp = w0 * sqrt((1.0 - ((h / l) * (((D / d) * (M / 2.0)) ^ 2.0))));
	else
		tmp = w0 * (1.0 + (((D * (D * ((M / d) * ((h * M) / d)))) / 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[(h / l), $MachinePrecision], (-Infinity)], N[(w0 * N[Sqrt[N[(1.0 - N[(N[(D / d), $MachinePrecision] * N[(N[(D / N[(l / N[(M * N[(h * M), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(0.25 / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(h / l), $MachinePrecision], -2e-30], N[(w0 * N[Sqrt[N[(1.0 - N[(N[(h / l), $MachinePrecision] * N[Power[N[(N[(D / d), $MachinePrecision] * N[(M / 2.0), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(w0 * N[(1.0 + N[(N[(N[(D * N[(D * N[(N[(M / d), $MachinePrecision] * N[(N[(h * M), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision] * -0.125), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
M = |M|\\
D = |D|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\begin{array}{l}
\mathbf{if}\;\frac{h}{\ell} \leq -\infty:\\
\;\;\;\;w0 \cdot \sqrt{1 - \frac{D}{d} \cdot \left(\frac{D}{\frac{\ell}{M \cdot \left(h \cdot M\right)}} \cdot \frac{0.25}{d}\right)}\\

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

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


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

    1. Initial program 44.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. times-frac44.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -inf.0 < (/.f64 h l) < -2e-30

    1. Initial program 84.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. times-frac84.4%

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

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

    if -2e-30 < (/.f64 h l)

    1. Initial program 88.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. times-frac88.3%

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

      \[\leadsto \color{blue}{w0 \cdot \sqrt{1 - {\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}}} \]
    4. Taylor expanded in M around 0 58.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. associate-*r/58.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 86.1% 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^{-30}:\\ \;\;\;\;w0 \cdot \sqrt{1 - \frac{h \cdot {\left(\frac{M}{d} \cdot \left(D \cdot 0.5\right)\right)}^{2}}{\ell}}\\ \mathbf{else}:\\ \;\;\;\;w0 \cdot \left(1 + \frac{D \cdot \left(D \cdot \left(\frac{M}{d} \cdot \frac{h \cdot M}{d}\right)\right)}{\ell} \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 l) -2e-30)
   (* w0 (sqrt (- 1.0 (/ (* h (pow (* (/ M d) (* D 0.5)) 2.0)) l))))
   (* w0 (+ 1.0 (* (/ (* D (* D (* (/ M d) (/ (* h M) d)))) 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 / l) <= -2e-30) {
		tmp = w0 * sqrt((1.0 - ((h * pow(((M / d) * (D * 0.5)), 2.0)) / l)));
	} else {
		tmp = w0 * (1.0 + (((D * (D * ((M / d) * ((h * M) / d)))) / 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 / l) <= (-2d-30)) then
        tmp = w0 * sqrt((1.0d0 - ((h * (((m / d_1) * (d * 0.5d0)) ** 2.0d0)) / l)))
    else
        tmp = w0 * (1.0d0 + (((d * (d * ((m / d_1) * ((h * m) / d_1)))) / 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 / l) <= -2e-30) {
		tmp = w0 * Math.sqrt((1.0 - ((h * Math.pow(((M / d) * (D * 0.5)), 2.0)) / l)));
	} else {
		tmp = w0 * (1.0 + (((D * (D * ((M / d) * ((h * M) / d)))) / 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 / l) <= -2e-30:
		tmp = w0 * math.sqrt((1.0 - ((h * math.pow(((M / d) * (D * 0.5)), 2.0)) / l)))
	else:
		tmp = w0 * (1.0 + (((D * (D * ((M / d) * ((h * M) / d)))) / 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(h / l) <= -2e-30)
		tmp = Float64(w0 * sqrt(Float64(1.0 - Float64(Float64(h * (Float64(Float64(M / d) * Float64(D * 0.5)) ^ 2.0)) / l))));
	else
		tmp = Float64(w0 * Float64(1.0 + Float64(Float64(Float64(D * Float64(D * Float64(Float64(M / d) * Float64(Float64(h * M) / d)))) / 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 / l) <= -2e-30)
		tmp = w0 * sqrt((1.0 - ((h * (((M / d) * (D * 0.5)) ^ 2.0)) / l)));
	else
		tmp = w0 * (1.0 + (((D * (D * ((M / d) * ((h * M) / d)))) / 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[(h / l), $MachinePrecision], -2e-30], N[(w0 * N[Sqrt[N[(1.0 - N[(N[(h * N[Power[N[(N[(M / d), $MachinePrecision] * N[(D * 0.5), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(w0 * N[(1.0 + N[(N[(N[(D * N[(D * N[(N[(M / d), $MachinePrecision] * N[(N[(h * M), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision] * -0.125), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\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^{-30}:\\
\;\;\;\;w0 \cdot \sqrt{1 - \frac{h \cdot {\left(\frac{M}{d} \cdot \left(D \cdot 0.5\right)\right)}^{2}}{\ell}}\\

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


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

    1. Initial program 75.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. times-frac75.0%

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

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

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

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

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

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

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

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

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

    if -2e-30 < (/.f64 h l)

    1. Initial program 88.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. times-frac88.3%

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

      \[\leadsto \color{blue}{w0 \cdot \sqrt{1 - {\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}}} \]
    4. Taylor expanded in M around 0 58.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. associate-*r/58.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 81.8% accurate, 1.7× speedup?

\[\begin{array}{l} M = |M|\\ D = |D|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ \begin{array}{l} \mathbf{if}\;d \leq 7.2 \cdot 10^{-82}:\\ \;\;\;\;w0 \cdot \left(1 + -0.125 \cdot \frac{D \cdot \left(D \cdot \frac{h}{\frac{d}{M} \cdot \frac{d}{M}}\right)}{\ell}\right)\\ \mathbf{elif}\;d \leq 1.42 \cdot 10^{+115}:\\ \;\;\;\;w0 \cdot \sqrt{1 - \frac{0.25}{d} \cdot \frac{D \cdot \left(D \cdot \left(M \cdot \left(h \cdot M\right)\right)\right)}{\ell \cdot d}}\\ \mathbf{else}:\\ \;\;\;\;w0 \cdot \left(1 + -0.125 \cdot \frac{D \cdot \left(D \cdot \left(\frac{h}{d} \cdot \frac{M \cdot M}{d}\right)\right)}{\ell}\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 7.2e-82)
   (* w0 (+ 1.0 (* -0.125 (/ (* D (* D (/ h (* (/ d M) (/ d M))))) l))))
   (if (<= d 1.42e+115)
     (* w0 (sqrt (- 1.0 (* (/ 0.25 d) (/ (* D (* D (* M (* h M)))) (* l d))))))
     (* w0 (+ 1.0 (* -0.125 (/ (* D (* D (* (/ h d) (/ (* M M) 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 (d <= 7.2e-82) {
		tmp = w0 * (1.0 + (-0.125 * ((D * (D * (h / ((d / M) * (d / M))))) / l)));
	} else if (d <= 1.42e+115) {
		tmp = w0 * sqrt((1.0 - ((0.25 / d) * ((D * (D * (M * (h * M)))) / (l * d)))));
	} else {
		tmp = w0 * (1.0 + (-0.125 * ((D * (D * ((h / d) * ((M * M) / 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 (d_1 <= 7.2d-82) then
        tmp = w0 * (1.0d0 + ((-0.125d0) * ((d * (d * (h / ((d_1 / m) * (d_1 / m))))) / l)))
    else if (d_1 <= 1.42d+115) then
        tmp = w0 * sqrt((1.0d0 - ((0.25d0 / d_1) * ((d * (d * (m * (h * m)))) / (l * d_1)))))
    else
        tmp = w0 * (1.0d0 + ((-0.125d0) * ((d * (d * ((h / d_1) * ((m * m) / 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 (d <= 7.2e-82) {
		tmp = w0 * (1.0 + (-0.125 * ((D * (D * (h / ((d / M) * (d / M))))) / l)));
	} else if (d <= 1.42e+115) {
		tmp = w0 * Math.sqrt((1.0 - ((0.25 / d) * ((D * (D * (M * (h * M)))) / (l * d)))));
	} else {
		tmp = w0 * (1.0 + (-0.125 * ((D * (D * ((h / d) * ((M * M) / 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 d <= 7.2e-82:
		tmp = w0 * (1.0 + (-0.125 * ((D * (D * (h / ((d / M) * (d / M))))) / l)))
	elif d <= 1.42e+115:
		tmp = w0 * math.sqrt((1.0 - ((0.25 / d) * ((D * (D * (M * (h * M)))) / (l * d)))))
	else:
		tmp = w0 * (1.0 + (-0.125 * ((D * (D * ((h / d) * ((M * M) / 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 (d <= 7.2e-82)
		tmp = Float64(w0 * Float64(1.0 + Float64(-0.125 * Float64(Float64(D * Float64(D * Float64(h / Float64(Float64(d / M) * Float64(d / M))))) / l))));
	elseif (d <= 1.42e+115)
		tmp = Float64(w0 * sqrt(Float64(1.0 - Float64(Float64(0.25 / d) * Float64(Float64(D * Float64(D * Float64(M * Float64(h * M)))) / Float64(l * d))))));
	else
		tmp = Float64(w0 * Float64(1.0 + Float64(-0.125 * Float64(Float64(D * Float64(D * Float64(Float64(h / d) * Float64(Float64(M * M) / 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 (d <= 7.2e-82)
		tmp = w0 * (1.0 + (-0.125 * ((D * (D * (h / ((d / M) * (d / M))))) / l)));
	elseif (d <= 1.42e+115)
		tmp = w0 * sqrt((1.0 - ((0.25 / d) * ((D * (D * (M * (h * M)))) / (l * d)))));
	else
		tmp = w0 * (1.0 + (-0.125 * ((D * (D * ((h / d) * ((M * M) / 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[d, 7.2e-82], N[(w0 * N[(1.0 + N[(-0.125 * N[(N[(D * N[(D * N[(h / N[(N[(d / M), $MachinePrecision] * N[(d / M), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.42e+115], N[(w0 * N[Sqrt[N[(1.0 - N[(N[(0.25 / d), $MachinePrecision] * N[(N[(D * N[(D * N[(M * N[(h * M), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(l * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(w0 * N[(1.0 + N[(-0.125 * N[(N[(D * N[(D * N[(N[(h / d), $MachinePrecision] * N[(N[(M * M), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
M = |M|\\
D = |D|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\begin{array}{l}
\mathbf{if}\;d \leq 7.2 \cdot 10^{-82}:\\
\;\;\;\;w0 \cdot \left(1 + -0.125 \cdot \frac{D \cdot \left(D \cdot \frac{h}{\frac{d}{M} \cdot \frac{d}{M}}\right)}{\ell}\right)\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < 7.19999999999999996e-82

    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. times-frac81.8%

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

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

      \[\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. associate-*r/48.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 7.19999999999999996e-82 < d < 1.42e115

    1. Initial program 79.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. times-frac79.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.42e115 < d

    1. Initial program 91.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. times-frac91.7%

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

      \[\leadsto \color{blue}{w0 \cdot \sqrt{1 - {\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}}} \]
    4. Taylor expanded in M around 0 62.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. associate-*r/62.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 83.7% accurate, 1.8× speedup?

\[\begin{array}{l} M = |M|\\ D = |D|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ \begin{array}{l} \mathbf{if}\;M \leq 5 \cdot 10^{-151}:\\ \;\;\;\;w0 \cdot \left(1 + -0.125 \cdot \frac{D \cdot \left(D \cdot \frac{h}{\frac{d}{M} \cdot \frac{d}{M}}\right)}{\ell}\right)\\ \mathbf{else}:\\ \;\;\;\;w0 \cdot \sqrt{1 - \frac{D}{d} \cdot \left(\frac{D}{\frac{\ell}{M \cdot \left(h \cdot M\right)}} \cdot \frac{0.25}{d}\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 5e-151)
   (* w0 (+ 1.0 (* -0.125 (/ (* D (* D (/ h (* (/ d M) (/ d M))))) l))))
   (* w0 (sqrt (- 1.0 (* (/ D d) (* (/ D (/ l (* M (* h M)))) (/ 0.25 d))))))))
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 <= 5e-151) {
		tmp = w0 * (1.0 + (-0.125 * ((D * (D * (h / ((d / M) * (d / M))))) / l)));
	} else {
		tmp = w0 * sqrt((1.0 - ((D / d) * ((D / (l / (M * (h * M)))) * (0.25 / d)))));
	}
	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 <= 5d-151) then
        tmp = w0 * (1.0d0 + ((-0.125d0) * ((d * (d * (h / ((d_1 / m) * (d_1 / m))))) / l)))
    else
        tmp = w0 * sqrt((1.0d0 - ((d / d_1) * ((d / (l / (m * (h * m)))) * (0.25d0 / d_1)))))
    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 <= 5e-151) {
		tmp = w0 * (1.0 + (-0.125 * ((D * (D * (h / ((d / M) * (d / M))))) / l)));
	} else {
		tmp = w0 * Math.sqrt((1.0 - ((D / d) * ((D / (l / (M * (h * M)))) * (0.25 / d)))));
	}
	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 <= 5e-151:
		tmp = w0 * (1.0 + (-0.125 * ((D * (D * (h / ((d / M) * (d / M))))) / l)))
	else:
		tmp = w0 * math.sqrt((1.0 - ((D / d) * ((D / (l / (M * (h * M)))) * (0.25 / d)))))
	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 <= 5e-151)
		tmp = Float64(w0 * Float64(1.0 + Float64(-0.125 * Float64(Float64(D * Float64(D * Float64(h / Float64(Float64(d / M) * Float64(d / M))))) / l))));
	else
		tmp = Float64(w0 * sqrt(Float64(1.0 - Float64(Float64(D / d) * Float64(Float64(D / Float64(l / Float64(M * Float64(h * M)))) * Float64(0.25 / d))))));
	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 <= 5e-151)
		tmp = w0 * (1.0 + (-0.125 * ((D * (D * (h / ((d / M) * (d / M))))) / l)));
	else
		tmp = w0 * sqrt((1.0 - ((D / d) * ((D / (l / (M * (h * M)))) * (0.25 / d)))));
	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, 5e-151], N[(w0 * N[(1.0 + N[(-0.125 * N[(N[(D * N[(D * N[(h / N[(N[(d / M), $MachinePrecision] * N[(d / M), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(w0 * N[Sqrt[N[(1.0 - N[(N[(D / d), $MachinePrecision] * N[(N[(D / N[(l / N[(M * N[(h * M), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(0.25 / d), $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 5 \cdot 10^{-151}:\\
\;\;\;\;w0 \cdot \left(1 + -0.125 \cdot \frac{D \cdot \left(D \cdot \frac{h}{\frac{d}{M} \cdot \frac{d}{M}}\right)}{\ell}\right)\\

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


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

    1. Initial program 86.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. times-frac86.8%

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

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

      \[\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. associate-*r/59.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 5.00000000000000003e-151 < M

    1. Initial program 77.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. times-frac77.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto w0 \cdot \color{blue}{\left(1 \cdot \sqrt{1 - \left(\frac{D}{d} \cdot \frac{D \cdot \left(M \cdot \left(M \cdot h\right)\right)}{\ell}\right) \cdot \frac{0.25}{d}}\right)} \]
    14. Step-by-step derivation
      1. *-lft-identity66.6%

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

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

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

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

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

Alternative 7: 73.1% 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.1 \cdot 10^{-253}:\\ \;\;\;\;w0 \cdot \sqrt{1 - \frac{0.25 \cdot \left(\frac{D \cdot D}{\ell} \cdot \left(M \cdot \left(M \cdot \frac{h}{d}\right)\right)\right)}{d}}\\ \mathbf{else}:\\ \;\;\;\;w0 \cdot \sqrt{1 - \frac{D}{d} \cdot \left(\frac{D}{\frac{\ell}{M \cdot \left(h \cdot M\right)}} \cdot \frac{0.25}{d}\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.1e-253)
   (* w0 (sqrt (- 1.0 (/ (* 0.25 (* (/ (* D D) l) (* M (* M (/ h d))))) d))))
   (* w0 (sqrt (- 1.0 (* (/ D d) (* (/ D (/ l (* M (* h M)))) (/ 0.25 d))))))))
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.1e-253) {
		tmp = w0 * sqrt((1.0 - ((0.25 * (((D * D) / l) * (M * (M * (h / d))))) / d)));
	} else {
		tmp = w0 * sqrt((1.0 - ((D / d) * ((D / (l / (M * (h * M)))) * (0.25 / d)))));
	}
	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.1d-253) then
        tmp = w0 * sqrt((1.0d0 - ((0.25d0 * (((d * d) / l) * (m * (m * (h / d_1))))) / d_1)))
    else
        tmp = w0 * sqrt((1.0d0 - ((d / d_1) * ((d / (l / (m * (h * m)))) * (0.25d0 / d_1)))))
    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.1e-253) {
		tmp = w0 * Math.sqrt((1.0 - ((0.25 * (((D * D) / l) * (M * (M * (h / d))))) / d)));
	} else {
		tmp = w0 * Math.sqrt((1.0 - ((D / d) * ((D / (l / (M * (h * M)))) * (0.25 / d)))));
	}
	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.1e-253:
		tmp = w0 * math.sqrt((1.0 - ((0.25 * (((D * D) / l) * (M * (M * (h / d))))) / d)))
	else:
		tmp = w0 * math.sqrt((1.0 - ((D / d) * ((D / (l / (M * (h * M)))) * (0.25 / d)))))
	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.1e-253)
		tmp = Float64(w0 * sqrt(Float64(1.0 - Float64(Float64(0.25 * Float64(Float64(Float64(D * D) / l) * Float64(M * Float64(M * Float64(h / d))))) / d))));
	else
		tmp = Float64(w0 * sqrt(Float64(1.0 - Float64(Float64(D / d) * Float64(Float64(D / Float64(l / Float64(M * Float64(h * M)))) * Float64(0.25 / d))))));
	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.1e-253)
		tmp = w0 * sqrt((1.0 - ((0.25 * (((D * D) / l) * (M * (M * (h / d))))) / d)));
	else
		tmp = w0 * sqrt((1.0 - ((D / d) * ((D / (l / (M * (h * M)))) * (0.25 / d)))));
	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.1e-253], N[(w0 * N[Sqrt[N[(1.0 - N[(N[(0.25 * N[(N[(N[(D * D), $MachinePrecision] / l), $MachinePrecision] * N[(M * N[(M * N[(h / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(w0 * N[Sqrt[N[(1.0 - N[(N[(D / d), $MachinePrecision] * N[(N[(D / N[(l / N[(M * N[(h * M), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(0.25 / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
M = |M|\\
D = |D|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\begin{array}{l}
\mathbf{if}\;d \leq 4.1 \cdot 10^{-253}:\\
\;\;\;\;w0 \cdot \sqrt{1 - \frac{0.25 \cdot \left(\frac{D \cdot D}{\ell} \cdot \left(M \cdot \left(M \cdot \frac{h}{d}\right)\right)\right)}{d}}\\

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


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

    1. Initial program 81.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. times-frac81.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\frac{0.25 \cdot \left(h \cdot \left(\left(D \cdot M\right) \cdot \left(D \cdot M\right)\right)\right)}{d \cdot \left(d \cdot \ell\right)}}} \]
    7. Step-by-step derivation
      1. *-un-lft-identity71.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 4.10000000000000002e-253 < d

    1. Initial program 84.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. times-frac84.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto w0 \cdot \color{blue}{\left(1 \cdot \sqrt{1 - \left(\frac{D}{d} \cdot \frac{D \cdot \left(M \cdot \left(M \cdot h\right)\right)}{\ell}\right) \cdot \frac{0.25}{d}}\right)} \]
    14. Step-by-step derivation
      1. *-lft-identity80.4%

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

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

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

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

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

Alternative 8: 70.1% accurate, 7.9× speedup?

\[\begin{array}{l} M = |M|\\ D = |D|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ \begin{array}{l} \mathbf{if}\;M \leq 3.9 \cdot 10^{-147}:\\ \;\;\;\;w0\\ \mathbf{elif}\;M \leq 12500000 \lor \neg \left(M \leq 1.3 \cdot 10^{+38}\right):\\ \;\;\;\;w0 \cdot \left(1 + -0.125 \cdot \left(\frac{D \cdot D}{\ell} \cdot \frac{h \cdot \left(M \cdot M\right)}{d \cdot d}\right)\right)\\ \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 (<= M 3.9e-147)
   w0
   (if (or (<= M 12500000.0) (not (<= M 1.3e+38)))
     (* w0 (+ 1.0 (* -0.125 (* (/ (* D D) l) (/ (* h (* M M)) (* d d))))))
     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 (M <= 3.9e-147) {
		tmp = w0;
	} else if ((M <= 12500000.0) || !(M <= 1.3e+38)) {
		tmp = w0 * (1.0 + (-0.125 * (((D * D) / l) * ((h * (M * M)) / (d * d)))));
	} 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) :: tmp
    if (m <= 3.9d-147) then
        tmp = w0
    else if ((m <= 12500000.0d0) .or. (.not. (m <= 1.3d+38))) then
        tmp = w0 * (1.0d0 + ((-0.125d0) * (((d * d) / l) * ((h * (m * m)) / (d_1 * d_1)))))
    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 tmp;
	if (M <= 3.9e-147) {
		tmp = w0;
	} else if ((M <= 12500000.0) || !(M <= 1.3e+38)) {
		tmp = w0 * (1.0 + (-0.125 * (((D * D) / l) * ((h * (M * M)) / (d * d)))));
	} else {
		tmp = w0;
	}
	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.9e-147:
		tmp = w0
	elif (M <= 12500000.0) or not (M <= 1.3e+38):
		tmp = w0 * (1.0 + (-0.125 * (((D * D) / l) * ((h * (M * M)) / (d * d)))))
	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 (M <= 3.9e-147)
		tmp = w0;
	elseif ((M <= 12500000.0) || !(M <= 1.3e+38))
		tmp = Float64(w0 * Float64(1.0 + Float64(-0.125 * Float64(Float64(Float64(D * D) / l) * Float64(Float64(h * Float64(M * M)) / Float64(d * d))))));
	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)
	tmp = 0.0;
	if (M <= 3.9e-147)
		tmp = w0;
	elseif ((M <= 12500000.0) || ~((M <= 1.3e+38)))
		tmp = w0 * (1.0 + (-0.125 * (((D * D) / l) * ((h * (M * M)) / (d * d)))));
	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_] := If[LessEqual[M, 3.9e-147], w0, If[Or[LessEqual[M, 12500000.0], N[Not[LessEqual[M, 1.3e+38]], $MachinePrecision]], N[(w0 * N[(1.0 + N[(-0.125 * N[(N[(N[(D * D), $MachinePrecision] / l), $MachinePrecision] * N[(N[(h * N[(M * M), $MachinePrecision]), $MachinePrecision] / N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], w0]]
\begin{array}{l}
M = |M|\\
D = |D|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\begin{array}{l}
\mathbf{if}\;M \leq 3.9 \cdot 10^{-147}:\\
\;\;\;\;w0\\

\mathbf{elif}\;M \leq 12500000 \lor \neg \left(M \leq 1.3 \cdot 10^{+38}\right):\\
\;\;\;\;w0 \cdot \left(1 + -0.125 \cdot \left(\frac{D \cdot D}{\ell} \cdot \frac{h \cdot \left(M \cdot M\right)}{d \cdot d}\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if M < 3.8999999999999998e-147 or 1.25e7 < M < 1.3e38

    1. Initial program 86.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. times-frac86.7%

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

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

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

    if 3.8999999999999998e-147 < M < 1.25e7 or 1.3e38 < M

    1. Initial program 76.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. times-frac76.4%

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

      \[\leadsto \color{blue}{w0 \cdot \sqrt{1 - {\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}}} \]
    4. Taylor expanded in M around 0 43.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. associate-*r/43.7%

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;M \leq 3.9 \cdot 10^{-147}:\\ \;\;\;\;w0\\ \mathbf{elif}\;M \leq 12500000 \lor \neg \left(M \leq 1.3 \cdot 10^{+38}\right):\\ \;\;\;\;w0 \cdot \left(1 + -0.125 \cdot \left(\frac{D \cdot D}{\ell} \cdot \frac{h \cdot \left(M \cdot M\right)}{d \cdot d}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;w0\\ \end{array} \]

Alternative 9: 75.3% 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.8 \cdot 10^{-151}:\\ \;\;\;\;w0\\ \mathbf{else}:\\ \;\;\;\;w0 \cdot \left(1 + -0.125 \cdot \frac{D \cdot \left(D \cdot \left(M \cdot \left(h \cdot M\right)\right)\right)}{d \cdot \left(\ell \cdot d\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 4.8e-151)
   w0
   (* w0 (+ 1.0 (* -0.125 (/ (* D (* D (* M (* h M)))) (* d (* l d))))))))
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 <= 4.8e-151) {
		tmp = w0;
	} else {
		tmp = w0 * (1.0 + (-0.125 * ((D * (D * (M * (h * M)))) / (d * (l * d)))));
	}
	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 <= 4.8d-151) then
        tmp = w0
    else
        tmp = w0 * (1.0d0 + ((-0.125d0) * ((d * (d * (m * (h * m)))) / (d_1 * (l * d_1)))))
    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 <= 4.8e-151) {
		tmp = w0;
	} else {
		tmp = w0 * (1.0 + (-0.125 * ((D * (D * (M * (h * M)))) / (d * (l * d)))));
	}
	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 <= 4.8e-151:
		tmp = w0
	else:
		tmp = w0 * (1.0 + (-0.125 * ((D * (D * (M * (h * M)))) / (d * (l * d)))))
	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 <= 4.8e-151)
		tmp = w0;
	else
		tmp = Float64(w0 * Float64(1.0 + Float64(-0.125 * Float64(Float64(D * Float64(D * Float64(M * Float64(h * M)))) / Float64(d * Float64(l * d))))));
	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 <= 4.8e-151)
		tmp = w0;
	else
		tmp = w0 * (1.0 + (-0.125 * ((D * (D * (M * (h * M)))) / (d * (l * d)))));
	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, 4.8e-151], w0, N[(w0 * N[(1.0 + N[(-0.125 * N[(N[(D * N[(D * N[(M * N[(h * M), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(d * N[(l * d), $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.8 \cdot 10^{-151}:\\
\;\;\;\;w0\\

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


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

    1. Initial program 86.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. times-frac86.8%

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

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

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

    if 4.8e-151 < M

    1. Initial program 77.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. times-frac77.1%

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

      \[\leadsto \color{blue}{w0 \cdot \sqrt{1 - {\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}}} \]
    4. Taylor expanded in M around 0 44.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. associate-*r/44.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 10: 72.6% accurate, 10.3× speedup?

\[\begin{array}{l} M = |M|\\ D = |D|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ \begin{array}{l} \mathbf{if}\;M \leq 1.4 \cdot 10^{+80}:\\ \;\;\;\;w0\\ \mathbf{else}:\\ \;\;\;\;-0.125 \cdot \left(\left(\frac{D}{d} \cdot \frac{D}{d}\right) \cdot \frac{w0 \cdot \left(M \cdot \left(h \cdot M\right)\right)}{\ell}\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 1.4e+80)
   w0
   (* -0.125 (* (* (/ D d) (/ D d)) (/ (* w0 (* M (* h 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 <= 1.4e+80) {
		tmp = w0;
	} else {
		tmp = -0.125 * (((D / d) * (D / d)) * ((w0 * (M * (h * 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 <= 1.4d+80) then
        tmp = w0
    else
        tmp = (-0.125d0) * (((d / d_1) * (d / d_1)) * ((w0 * (m * (h * 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 <= 1.4e+80) {
		tmp = w0;
	} else {
		tmp = -0.125 * (((D / d) * (D / d)) * ((w0 * (M * (h * 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 <= 1.4e+80:
		tmp = w0
	else:
		tmp = -0.125 * (((D / d) * (D / d)) * ((w0 * (M * (h * 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 <= 1.4e+80)
		tmp = w0;
	else
		tmp = Float64(-0.125 * Float64(Float64(Float64(D / d) * Float64(D / d)) * Float64(Float64(w0 * Float64(M * Float64(h * 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 <= 1.4e+80)
		tmp = w0;
	else
		tmp = -0.125 * (((D / d) * (D / d)) * ((w0 * (M * (h * 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, 1.4e+80], w0, N[(-0.125 * N[(N[(N[(D / d), $MachinePrecision] * N[(D / d), $MachinePrecision]), $MachinePrecision] * N[(N[(w0 * N[(M * N[(h * M), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
M = |M|\\
D = |D|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\begin{array}{l}
\mathbf{if}\;M \leq 1.4 \cdot 10^{+80}:\\
\;\;\;\;w0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if M < 1.39999999999999992e80

    1. Initial program 84.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. times-frac84.6%

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

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

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

    if 1.39999999999999992e80 < M

    1. Initial program 76.2%

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

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

      \[\leadsto \color{blue}{w0 \cdot \sqrt{1 - {\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}}} \]
    4. Taylor expanded in M around 0 30.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. associate-*r/30.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 11: 81.4% accurate, 10.3× speedup?

\[\begin{array}{l} M = |M|\\ D = |D|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ w0 \cdot \left(1 + \frac{D \cdot \left(D \cdot \left(\frac{M}{d} \cdot \frac{h \cdot M}{d}\right)\right)}{\ell} \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 (* (/ M d) (/ (* h M) d)))) 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 * ((M / d) * ((h * M) / d)))) / 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 * ((m / d_1) * ((h * m) / d_1)))) / 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 * ((M / d) * ((h * M) / d)))) / 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 * ((M / d) * ((h * M) / d)))) / 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(Float64(D * Float64(D * Float64(Float64(M / d) * Float64(Float64(h * M) / d)))) / 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 * ((M / d) * ((h * M) / d)))) / 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[(N[(D * N[(D * N[(N[(M / d), $MachinePrecision] * N[(N[(h * M), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision] * -0.125), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
M = |M|\\
D = |D|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
w0 \cdot \left(1 + \frac{D \cdot \left(D \cdot \left(\frac{M}{d} \cdot \frac{h \cdot M}{d}\right)\right)}{\ell} \cdot -0.125\right)
\end{array}
Derivation
  1. Initial program 83.2%

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

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

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

    \[\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. associate-*r/54.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 12: 68.6% 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 83.2%

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

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

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

    \[\leadsto \color{blue}{w0} \]
  5. Final simplification69.2%

    \[\leadsto w0 \]

Reproduce

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