Henrywood and Agarwal, Equation (9a)

Percentage Accurate: 81.2% → 87.0%
Time: 16.1s
Alternatives: 8
Speedup: 1.0×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 8 alternatives:

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

Initial Program: 81.2% 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: 87.0% accurate, 0.7× speedup?

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

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


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

    1. Initial program 86.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.9999999999999988e-309 < h

    1. Initial program 79.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 87.1% accurate, 0.7× speedup?

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

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


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

    1. Initial program 86.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -9.9999999999999991e-309 < h

    1. Initial program 79.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 87.0% accurate, 0.7× speedup?

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

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


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

    1. Initial program 86.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -9.9999999999999991e-309 < h

    1. Initial program 79.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 87.0% accurate, 0.7× speedup?

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

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


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

    1. Initial program 86.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -9.9999999999999991e-309 < h

    1. Initial program 79.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 86.2% accurate, 1.0× speedup?

\[\begin{array}{l} M = |M|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ w0 \cdot \sqrt{1 - h \cdot \frac{{\left(\frac{M}{d \cdot \frac{2}{D}}\right)}^{2}}{\ell}} \end{array} \]
NOTE: M should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
(FPCore (w0 M D h l d)
 :precision binary64
 (* w0 (sqrt (- 1.0 (* h (/ (pow (/ M (* d (/ 2.0 D))) 2.0) l))))))
M = abs(M);
assert(M < D);
double code(double w0, double M, double D, double h, double l, double d) {
	return w0 * sqrt((1.0 - (h * (pow((M / (d * (2.0 / D))), 2.0) / l))));
}
NOTE: M should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
real(8) function code(w0, m, d, h, l, d_1)
    real(8), intent (in) :: w0
    real(8), intent (in) :: m
    real(8), intent (in) :: d
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: d_1
    code = w0 * sqrt((1.0d0 - (h * (((m / (d_1 * (2.0d0 / d))) ** 2.0d0) / l))))
end function
M = Math.abs(M);
assert M < D;
public static double code(double w0, double M, double D, double h, double l, double d) {
	return w0 * Math.sqrt((1.0 - (h * (Math.pow((M / (d * (2.0 / D))), 2.0) / l))));
}
M = abs(M)
[M, D] = sort([M, D])
def code(w0, M, D, h, l, d):
	return w0 * math.sqrt((1.0 - (h * (math.pow((M / (d * (2.0 / D))), 2.0) / l))))
M = abs(M)
M, D = sort([M, D])
function code(w0, M, D, h, l, d)
	return Float64(w0 * sqrt(Float64(1.0 - Float64(h * Float64((Float64(M / Float64(d * Float64(2.0 / D))) ^ 2.0) / l)))))
end
M = abs(M)
M, D = num2cell(sort([M, D])){:}
function tmp = code(w0, M, D, h, l, d)
	tmp = w0 * sqrt((1.0 - (h * (((M / (d * (2.0 / D))) ^ 2.0) / l))));
end
NOTE: M should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
code[w0_, M_, D_, h_, l_, d_] := N[(w0 * N[Sqrt[N[(1.0 - N[(h * N[(N[Power[N[(M / N[(d * N[(2.0 / D), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
M = |M|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
w0 \cdot \sqrt{1 - h \cdot \frac{{\left(\frac{M}{d \cdot \frac{2}{D}}\right)}^{2}}{\ell}}
\end{array}
Derivation
  1. Initial program 82.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 72.7% accurate, 9.4× speedup?

\[\begin{array}{l} M = |M|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ \begin{array}{l} \mathbf{if}\;D \leq 520000:\\ \;\;\;\;w0\\ \mathbf{else}:\\ \;\;\;\;w0 + -0.125 \cdot \left(\frac{\left(D \cdot M\right) \cdot \left(D \cdot M\right)}{\ell} \cdot \left(\frac{h}{d} \cdot \frac{w0}{d}\right)\right)\\ \end{array} \end{array} \]
NOTE: M 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 520000.0)
   w0
   (+ w0 (* -0.125 (* (/ (* (* D M) (* D M)) l) (* (/ h d) (/ w0 d)))))))
M = abs(M);
assert(M < D);
double code(double w0, double M, double D, double h, double l, double d) {
	double tmp;
	if (D <= 520000.0) {
		tmp = w0;
	} else {
		tmp = w0 + (-0.125 * ((((D * M) * (D * M)) / l) * ((h / d) * (w0 / d))));
	}
	return tmp;
}
NOTE: M 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 <= 520000.0d0) then
        tmp = w0
    else
        tmp = w0 + ((-0.125d0) * ((((d * m) * (d * m)) / l) * ((h / d_1) * (w0 / d_1))))
    end if
    code = tmp
end function
M = Math.abs(M);
assert M < D;
public static double code(double w0, double M, double D, double h, double l, double d) {
	double tmp;
	if (D <= 520000.0) {
		tmp = w0;
	} else {
		tmp = w0 + (-0.125 * ((((D * M) * (D * M)) / l) * ((h / d) * (w0 / d))));
	}
	return tmp;
}
M = abs(M)
[M, D] = sort([M, D])
def code(w0, M, D, h, l, d):
	tmp = 0
	if D <= 520000.0:
		tmp = w0
	else:
		tmp = w0 + (-0.125 * ((((D * M) * (D * M)) / l) * ((h / d) * (w0 / d))))
	return tmp
M = abs(M)
M, D = sort([M, D])
function code(w0, M, D, h, l, d)
	tmp = 0.0
	if (D <= 520000.0)
		tmp = w0;
	else
		tmp = Float64(w0 + Float64(-0.125 * Float64(Float64(Float64(Float64(D * M) * Float64(D * M)) / l) * Float64(Float64(h / d) * Float64(w0 / d)))));
	end
	return tmp
end
M = abs(M)
M, D = num2cell(sort([M, D])){:}
function tmp_2 = code(w0, M, D, h, l, d)
	tmp = 0.0;
	if (D <= 520000.0)
		tmp = w0;
	else
		tmp = w0 + (-0.125 * ((((D * M) * (D * M)) / l) * ((h / d) * (w0 / d))));
	end
	tmp_2 = tmp;
end
NOTE: M 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, 520000.0], w0, N[(w0 + N[(-0.125 * N[(N[(N[(N[(D * M), $MachinePrecision] * N[(D * M), $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision] * N[(N[(h / d), $MachinePrecision] * N[(w0 / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
M = |M|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\begin{array}{l}
\mathbf{if}\;D \leq 520000:\\
\;\;\;\;w0\\

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


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

    1. Initial program 86.5%

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

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

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

    if 5.2e5 < D

    1. Initial program 70.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 76.9% accurate, 9.4× speedup?

\[\begin{array}{l} M = |M|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ \begin{array}{l} \mathbf{if}\;D \leq 4.2 \cdot 10^{-51}:\\ \;\;\;\;w0\\ \mathbf{else}:\\ \;\;\;\;w0 + -0.125 \cdot \frac{\left(D \cdot M\right) \cdot \left(w0 \cdot \frac{h}{d}\right)}{d \cdot \frac{\ell}{D \cdot M}}\\ \end{array} \end{array} \]
NOTE: M 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.2e-51)
   w0
   (+ w0 (* -0.125 (/ (* (* D M) (* w0 (/ h d))) (* d (/ l (* D M))))))))
M = abs(M);
assert(M < D);
double code(double w0, double M, double D, double h, double l, double d) {
	double tmp;
	if (D <= 4.2e-51) {
		tmp = w0;
	} else {
		tmp = w0 + (-0.125 * (((D * M) * (w0 * (h / d))) / (d * (l / (D * M)))));
	}
	return tmp;
}
NOTE: M 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 <= 4.2d-51) then
        tmp = w0
    else
        tmp = w0 + ((-0.125d0) * (((d * m) * (w0 * (h / d_1))) / (d_1 * (l / (d * m)))))
    end if
    code = tmp
end function
M = Math.abs(M);
assert M < D;
public static double code(double w0, double M, double D, double h, double l, double d) {
	double tmp;
	if (D <= 4.2e-51) {
		tmp = w0;
	} else {
		tmp = w0 + (-0.125 * (((D * M) * (w0 * (h / d))) / (d * (l / (D * M)))));
	}
	return tmp;
}
M = abs(M)
[M, D] = sort([M, D])
def code(w0, M, D, h, l, d):
	tmp = 0
	if D <= 4.2e-51:
		tmp = w0
	else:
		tmp = w0 + (-0.125 * (((D * M) * (w0 * (h / d))) / (d * (l / (D * M)))))
	return tmp
M = abs(M)
M, D = sort([M, D])
function code(w0, M, D, h, l, d)
	tmp = 0.0
	if (D <= 4.2e-51)
		tmp = w0;
	else
		tmp = Float64(w0 + Float64(-0.125 * Float64(Float64(Float64(D * M) * Float64(w0 * Float64(h / d))) / Float64(d * Float64(l / Float64(D * M))))));
	end
	return tmp
end
M = abs(M)
M, D = num2cell(sort([M, D])){:}
function tmp_2 = code(w0, M, D, h, l, d)
	tmp = 0.0;
	if (D <= 4.2e-51)
		tmp = w0;
	else
		tmp = w0 + (-0.125 * (((D * M) * (w0 * (h / d))) / (d * (l / (D * M)))));
	end
	tmp_2 = tmp;
end
NOTE: M 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.2e-51], w0, N[(w0 + N[(-0.125 * N[(N[(N[(D * M), $MachinePrecision] * N[(w0 * N[(h / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(d * N[(l / N[(D * M), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
M = |M|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\begin{array}{l}
\mathbf{if}\;D \leq 4.2 \cdot 10^{-51}:\\
\;\;\;\;w0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if D < 4.20000000000000003e-51

    1. Initial program 87.0%

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

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

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

    if 4.20000000000000003e-51 < D

    1. Initial program 71.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 67.9% accurate, 216.0× speedup?

\[\begin{array}{l} M = |M|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ w0 \end{array} \]
NOTE: M 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);
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: 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);
assert M < D;
public static double code(double w0, double M, double D, double h, double l, double d) {
	return w0;
}
M = abs(M)
[M, D] = sort([M, D])
def code(w0, M, D, h, l, d):
	return w0
M = abs(M)
M, D = sort([M, D])
function code(w0, M, D, h, l, d)
	return w0
end
M = abs(M)
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: 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|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
w0
\end{array}
Derivation
  1. Initial program 82.8%

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

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

    \[\leadsto \color{blue}{w0} \]
  4. Final simplification65.5%

    \[\leadsto w0 \]

Reproduce

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