Henrywood and Agarwal, Equation (9a)

Percentage Accurate: 81.0% → 87.1%
Time: 14.6s
Alternatives: 9
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 9 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.0% 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.1% accurate, 0.7× speedup?

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


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

    1. Initial program 99.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. *-commutative99.9%

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

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

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

    if 5.00000000000000009e183 < (-.f64 1 (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 2 d)) 2) (/.f64 h l)))

    1. Initial program 56.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. *-commutative56.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;1 - {\left(\frac{D \cdot M}{d \cdot 2}\right)}^{2} \cdot \frac{h}{\ell} \leq 5 \cdot 10^{+183}:\\ \;\;\;\;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{h \cdot {\left(0.5 \cdot \left(M \cdot \frac{D}{d}\right)\right)}^{2}}{\ell}}\\ \end{array} \]

Alternative 2: 86.9% accurate, 0.7× speedup?

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

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


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

    1. Initial program 92.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. *-commutative92.2%

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

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

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

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

    1. Initial program 0.0%

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

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

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

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

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

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

Alternative 3: 86.3% accurate, 1.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 76.9% accurate, 1.8× speedup?

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

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


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

    1. Initial program 83.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. *-commutative83.3%

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

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

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

      \[\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/59.1%

        \[\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. *-commutative59.1%

        \[\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. times-frac64.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 4.9999999999999998e-73 < d

    1. Initial program 87.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. *-commutative87.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 80.2% accurate, 1.9× speedup?

\[\begin{array}{l} M = |M|\\ D = |D|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ w0 \cdot \left(1 + \left(h \cdot \frac{{\left(M \cdot \frac{D}{d}\right)}^{2}}{\ell}\right) \cdot -0.125\right) \end{array} \]
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
(FPCore (w0 M D h l d)
 :precision binary64
 (* w0 (+ 1.0 (* (* h (/ (pow (* M (/ D d)) 2.0) 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 + ((h * (pow((M * (D / d)), 2.0) / 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 + ((h * (((m * (d / d_1)) ** 2.0d0) / 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 + ((h * (Math.pow((M * (D / d)), 2.0) / 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 + ((h * (math.pow((M * (D / d)), 2.0) / 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(h * Float64((Float64(M * Float64(D / d)) ^ 2.0) / 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 + ((h * (((M * (D / d)) ^ 2.0) / 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[(h * N[(N[Power[N[(M * N[(D / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision] * -0.125), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
M = |M|\\
D = |D|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
w0 \cdot \left(1 + \left(h \cdot \frac{{\left(M \cdot \frac{D}{d}\right)}^{2}}{\ell}\right) \cdot -0.125\right)
\end{array}
Derivation
  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. *-commutative84.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 77.5% accurate, 9.4× speedup?

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

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


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

    1. Initial program 86.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. *-commutative86.0%

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

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

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

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

    if 2.15000000000000009e-118 < M

    1. Initial program 82.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. *-commutative82.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 72.0% accurate, 10.3× speedup?

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

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


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

    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. *-commutative84.6%

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

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

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

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

    if 3.20000000000000011e63 < M

    1. Initial program 84.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. *-commutative84.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 77.8% accurate, 10.3× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 9: 68.5% 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 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. *-commutative84.6%

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

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

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

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

    \[\leadsto w0 \]

Reproduce

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