Henrywood and Agarwal, Equation (9a)

Percentage Accurate: 81.3% → 91.7%
Time: 14.2s
Alternatives: 10
Speedup: 1.8×

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 10 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.3% 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: 91.7% accurate, 0.6× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ d_m = \left|d\right| \\ [w0, M_m, D_m, h, l, d_m] = \mathsf{sort}([w0, M_m, D_m, h, l, d_m])\\ \\ \begin{array}{l} t_0 := {\left(\frac{M\_m \cdot D\_m}{2 \cdot d\_m}\right)}^{2} \cdot \frac{h}{\ell}\\ t_1 := \frac{d\_m}{D\_m \cdot M\_m}\\ \mathbf{if}\;t\_0 \leq -\infty:\\ \;\;\;\;D\_m \cdot \frac{\sqrt{M\_m \cdot \left(M\_m \cdot \frac{\frac{h}{\ell \cdot -4}}{d\_m}\right)} \cdot w0}{\sqrt{d\_m}}\\ \mathbf{elif}\;t\_0 \leq 2 \cdot 10^{-6}:\\ \;\;\;\;w0 \cdot \sqrt{1 - \frac{\frac{h}{\ell}}{4 \cdot \left(t\_1 \cdot t\_1\right)}}\\ \mathbf{else}:\\ \;\;\;\;w0 \cdot \sqrt{1 - \frac{\left(D\_m \cdot \left(h \cdot M\_m\right)\right) \cdot \left(\left(D\_m \cdot \frac{M\_m}{d\_m}\right) \cdot \frac{0.25}{d\_m}\right)}{\ell}}\\ \end{array} \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
d_m = (fabs.f64 d)
NOTE: w0, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
(FPCore (w0 M_m D_m h l d_m)
 :precision binary64
 (let* ((t_0 (* (pow (/ (* M_m D_m) (* 2.0 d_m)) 2.0) (/ h l)))
        (t_1 (/ d_m (* D_m M_m))))
   (if (<= t_0 (- INFINITY))
     (*
      D_m
      (/ (* (sqrt (* M_m (* M_m (/ (/ h (* l -4.0)) d_m)))) w0) (sqrt d_m)))
     (if (<= t_0 2e-6)
       (* w0 (sqrt (- 1.0 (/ (/ h l) (* 4.0 (* t_1 t_1))))))
       (*
        w0
        (sqrt
         (-
          1.0
          (/
           (* (* D_m (* h M_m)) (* (* D_m (/ M_m d_m)) (/ 0.25 d_m)))
           l))))))))
M_m = fabs(M);
D_m = fabs(D);
d_m = fabs(d);
assert(w0 < M_m && M_m < D_m && D_m < h && h < l && l < d_m);
double code(double w0, double M_m, double D_m, double h, double l, double d_m) {
	double t_0 = pow(((M_m * D_m) / (2.0 * d_m)), 2.0) * (h / l);
	double t_1 = d_m / (D_m * M_m);
	double tmp;
	if (t_0 <= -((double) INFINITY)) {
		tmp = D_m * ((sqrt((M_m * (M_m * ((h / (l * -4.0)) / d_m)))) * w0) / sqrt(d_m));
	} else if (t_0 <= 2e-6) {
		tmp = w0 * sqrt((1.0 - ((h / l) / (4.0 * (t_1 * t_1)))));
	} else {
		tmp = w0 * sqrt((1.0 - (((D_m * (h * M_m)) * ((D_m * (M_m / d_m)) * (0.25 / d_m))) / l)));
	}
	return tmp;
}
M_m = Math.abs(M);
D_m = Math.abs(D);
d_m = Math.abs(d);
assert w0 < M_m && M_m < D_m && D_m < h && h < l && l < d_m;
public static double code(double w0, double M_m, double D_m, double h, double l, double d_m) {
	double t_0 = Math.pow(((M_m * D_m) / (2.0 * d_m)), 2.0) * (h / l);
	double t_1 = d_m / (D_m * M_m);
	double tmp;
	if (t_0 <= -Double.POSITIVE_INFINITY) {
		tmp = D_m * ((Math.sqrt((M_m * (M_m * ((h / (l * -4.0)) / d_m)))) * w0) / Math.sqrt(d_m));
	} else if (t_0 <= 2e-6) {
		tmp = w0 * Math.sqrt((1.0 - ((h / l) / (4.0 * (t_1 * t_1)))));
	} else {
		tmp = w0 * Math.sqrt((1.0 - (((D_m * (h * M_m)) * ((D_m * (M_m / d_m)) * (0.25 / d_m))) / l)));
	}
	return tmp;
}
M_m = math.fabs(M)
D_m = math.fabs(D)
d_m = math.fabs(d)
[w0, M_m, D_m, h, l, d_m] = sort([w0, M_m, D_m, h, l, d_m])
def code(w0, M_m, D_m, h, l, d_m):
	t_0 = math.pow(((M_m * D_m) / (2.0 * d_m)), 2.0) * (h / l)
	t_1 = d_m / (D_m * M_m)
	tmp = 0
	if t_0 <= -math.inf:
		tmp = D_m * ((math.sqrt((M_m * (M_m * ((h / (l * -4.0)) / d_m)))) * w0) / math.sqrt(d_m))
	elif t_0 <= 2e-6:
		tmp = w0 * math.sqrt((1.0 - ((h / l) / (4.0 * (t_1 * t_1)))))
	else:
		tmp = w0 * math.sqrt((1.0 - (((D_m * (h * M_m)) * ((D_m * (M_m / d_m)) * (0.25 / d_m))) / l)))
	return tmp
M_m = abs(M)
D_m = abs(D)
d_m = abs(d)
w0, M_m, D_m, h, l, d_m = sort([w0, M_m, D_m, h, l, d_m])
function code(w0, M_m, D_m, h, l, d_m)
	t_0 = Float64((Float64(Float64(M_m * D_m) / Float64(2.0 * d_m)) ^ 2.0) * Float64(h / l))
	t_1 = Float64(d_m / Float64(D_m * M_m))
	tmp = 0.0
	if (t_0 <= Float64(-Inf))
		tmp = Float64(D_m * Float64(Float64(sqrt(Float64(M_m * Float64(M_m * Float64(Float64(h / Float64(l * -4.0)) / d_m)))) * w0) / sqrt(d_m)));
	elseif (t_0 <= 2e-6)
		tmp = Float64(w0 * sqrt(Float64(1.0 - Float64(Float64(h / l) / Float64(4.0 * Float64(t_1 * t_1))))));
	else
		tmp = Float64(w0 * sqrt(Float64(1.0 - Float64(Float64(Float64(D_m * Float64(h * M_m)) * Float64(Float64(D_m * Float64(M_m / d_m)) * Float64(0.25 / d_m))) / l))));
	end
	return tmp
end
M_m = abs(M);
D_m = abs(D);
d_m = abs(d);
w0, M_m, D_m, h, l, d_m = num2cell(sort([w0, M_m, D_m, h, l, d_m])){:}
function tmp_2 = code(w0, M_m, D_m, h, l, d_m)
	t_0 = (((M_m * D_m) / (2.0 * d_m)) ^ 2.0) * (h / l);
	t_1 = d_m / (D_m * M_m);
	tmp = 0.0;
	if (t_0 <= -Inf)
		tmp = D_m * ((sqrt((M_m * (M_m * ((h / (l * -4.0)) / d_m)))) * w0) / sqrt(d_m));
	elseif (t_0 <= 2e-6)
		tmp = w0 * sqrt((1.0 - ((h / l) / (4.0 * (t_1 * t_1)))));
	else
		tmp = w0 * sqrt((1.0 - (((D_m * (h * M_m)) * ((D_m * (M_m / d_m)) * (0.25 / d_m))) / l)));
	end
	tmp_2 = tmp;
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
d_m = N[Abs[d], $MachinePrecision]
NOTE: w0, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
code[w0_, M$95$m_, D$95$m_, h_, l_, d$95$m_] := Block[{t$95$0 = N[(N[Power[N[(N[(M$95$m * D$95$m), $MachinePrecision] / N[(2.0 * d$95$m), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(d$95$m / N[(D$95$m * M$95$m), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], N[(D$95$m * N[(N[(N[Sqrt[N[(M$95$m * N[(M$95$m * N[(N[(h / N[(l * -4.0), $MachinePrecision]), $MachinePrecision] / d$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * w0), $MachinePrecision] / N[Sqrt[d$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 2e-6], N[(w0 * N[Sqrt[N[(1.0 - N[(N[(h / l), $MachinePrecision] / N[(4.0 * N[(t$95$1 * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(w0 * N[Sqrt[N[(1.0 - N[(N[(N[(D$95$m * N[(h * M$95$m), $MachinePrecision]), $MachinePrecision] * N[(N[(D$95$m * N[(M$95$m / d$95$m), $MachinePrecision]), $MachinePrecision] * N[(0.25 / d$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
d_m = \left|d\right|
\\
[w0, M_m, D_m, h, l, d_m] = \mathsf{sort}([w0, M_m, D_m, h, l, d_m])\\
\\
\begin{array}{l}
t_0 := {\left(\frac{M\_m \cdot D\_m}{2 \cdot d\_m}\right)}^{2} \cdot \frac{h}{\ell}\\
t_1 := \frac{d\_m}{D\_m \cdot M\_m}\\
\mathbf{if}\;t\_0 \leq -\infty:\\
\;\;\;\;D\_m \cdot \frac{\sqrt{M\_m \cdot \left(M\_m \cdot \frac{\frac{h}{\ell \cdot -4}}{d\_m}\right)} \cdot w0}{\sqrt{d\_m}}\\

\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{-6}:\\
\;\;\;\;w0 \cdot \sqrt{1 - \frac{\frac{h}{\ell}}{4 \cdot \left(t\_1 \cdot t\_1\right)}}\\

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


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

    1. Initial program 49.6%

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

      \[\leadsto expr\]
    3. Add Preprocessing
    4. Taylor expanded in h around inf 0

      \[\leadsto expr\]
    5. Simplified0

      \[\leadsto expr\]
    6. Applied egg-rr0

      \[\leadsto expr\]
    7. Applied egg-rr0

      \[\leadsto expr\]
    8. Applied egg-rr0

      \[\leadsto expr\]

    if -inf.0 < (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) #s(literal 2 binary64)) (/.f64 h l)) < 1.99999999999999991e-6

    1. Initial program 99.9%

      \[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]
    2. Add Preprocessing
    3. Applied egg-rr0

      \[\leadsto expr\]

    if 1.99999999999999991e-6 < (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) #s(literal 2 binary64)) (/.f64 h l))

    1. Initial program 0.0%

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

      \[\leadsto expr\]
    3. Add Preprocessing
    4. Applied egg-rr0

      \[\leadsto expr\]
    5. Applied egg-rr0

      \[\leadsto expr\]
    6. Applied egg-rr0

      \[\leadsto expr\]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 2: 92.7% accurate, 0.6× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ d_m = \left|d\right| \\ [w0, M_m, D_m, h, l, d_m] = \mathsf{sort}([w0, M_m, D_m, h, l, d_m])\\ \\ \begin{array}{l} t_0 := {\left(\frac{M\_m \cdot D\_m}{2 \cdot d\_m}\right)}^{2} \cdot \frac{h}{\ell}\\ t_1 := \frac{d\_m}{D\_m \cdot M\_m}\\ \mathbf{if}\;t\_0 \leq -\infty:\\ \;\;\;\;D\_m \cdot \left(\sqrt{\frac{M\_m \cdot \frac{-0.25 \cdot \left(h \cdot \frac{M\_m}{d\_m}\right)}{\ell}}{d\_m}} \cdot w0\right)\\ \mathbf{elif}\;t\_0 \leq 2 \cdot 10^{-6}:\\ \;\;\;\;w0 \cdot \sqrt{1 - \frac{\frac{h}{\ell}}{4 \cdot \left(t\_1 \cdot t\_1\right)}}\\ \mathbf{else}:\\ \;\;\;\;w0 \cdot \sqrt{1 - \frac{\left(D\_m \cdot \left(h \cdot M\_m\right)\right) \cdot \left(\left(D\_m \cdot \frac{M\_m}{d\_m}\right) \cdot \frac{0.25}{d\_m}\right)}{\ell}}\\ \end{array} \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
d_m = (fabs.f64 d)
NOTE: w0, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
(FPCore (w0 M_m D_m h l d_m)
 :precision binary64
 (let* ((t_0 (* (pow (/ (* M_m D_m) (* 2.0 d_m)) 2.0) (/ h l)))
        (t_1 (/ d_m (* D_m M_m))))
   (if (<= t_0 (- INFINITY))
     (* D_m (* (sqrt (/ (* M_m (/ (* -0.25 (* h (/ M_m d_m))) l)) d_m)) w0))
     (if (<= t_0 2e-6)
       (* w0 (sqrt (- 1.0 (/ (/ h l) (* 4.0 (* t_1 t_1))))))
       (*
        w0
        (sqrt
         (-
          1.0
          (/
           (* (* D_m (* h M_m)) (* (* D_m (/ M_m d_m)) (/ 0.25 d_m)))
           l))))))))
M_m = fabs(M);
D_m = fabs(D);
d_m = fabs(d);
assert(w0 < M_m && M_m < D_m && D_m < h && h < l && l < d_m);
double code(double w0, double M_m, double D_m, double h, double l, double d_m) {
	double t_0 = pow(((M_m * D_m) / (2.0 * d_m)), 2.0) * (h / l);
	double t_1 = d_m / (D_m * M_m);
	double tmp;
	if (t_0 <= -((double) INFINITY)) {
		tmp = D_m * (sqrt(((M_m * ((-0.25 * (h * (M_m / d_m))) / l)) / d_m)) * w0);
	} else if (t_0 <= 2e-6) {
		tmp = w0 * sqrt((1.0 - ((h / l) / (4.0 * (t_1 * t_1)))));
	} else {
		tmp = w0 * sqrt((1.0 - (((D_m * (h * M_m)) * ((D_m * (M_m / d_m)) * (0.25 / d_m))) / l)));
	}
	return tmp;
}
M_m = Math.abs(M);
D_m = Math.abs(D);
d_m = Math.abs(d);
assert w0 < M_m && M_m < D_m && D_m < h && h < l && l < d_m;
public static double code(double w0, double M_m, double D_m, double h, double l, double d_m) {
	double t_0 = Math.pow(((M_m * D_m) / (2.0 * d_m)), 2.0) * (h / l);
	double t_1 = d_m / (D_m * M_m);
	double tmp;
	if (t_0 <= -Double.POSITIVE_INFINITY) {
		tmp = D_m * (Math.sqrt(((M_m * ((-0.25 * (h * (M_m / d_m))) / l)) / d_m)) * w0);
	} else if (t_0 <= 2e-6) {
		tmp = w0 * Math.sqrt((1.0 - ((h / l) / (4.0 * (t_1 * t_1)))));
	} else {
		tmp = w0 * Math.sqrt((1.0 - (((D_m * (h * M_m)) * ((D_m * (M_m / d_m)) * (0.25 / d_m))) / l)));
	}
	return tmp;
}
M_m = math.fabs(M)
D_m = math.fabs(D)
d_m = math.fabs(d)
[w0, M_m, D_m, h, l, d_m] = sort([w0, M_m, D_m, h, l, d_m])
def code(w0, M_m, D_m, h, l, d_m):
	t_0 = math.pow(((M_m * D_m) / (2.0 * d_m)), 2.0) * (h / l)
	t_1 = d_m / (D_m * M_m)
	tmp = 0
	if t_0 <= -math.inf:
		tmp = D_m * (math.sqrt(((M_m * ((-0.25 * (h * (M_m / d_m))) / l)) / d_m)) * w0)
	elif t_0 <= 2e-6:
		tmp = w0 * math.sqrt((1.0 - ((h / l) / (4.0 * (t_1 * t_1)))))
	else:
		tmp = w0 * math.sqrt((1.0 - (((D_m * (h * M_m)) * ((D_m * (M_m / d_m)) * (0.25 / d_m))) / l)))
	return tmp
M_m = abs(M)
D_m = abs(D)
d_m = abs(d)
w0, M_m, D_m, h, l, d_m = sort([w0, M_m, D_m, h, l, d_m])
function code(w0, M_m, D_m, h, l, d_m)
	t_0 = Float64((Float64(Float64(M_m * D_m) / Float64(2.0 * d_m)) ^ 2.0) * Float64(h / l))
	t_1 = Float64(d_m / Float64(D_m * M_m))
	tmp = 0.0
	if (t_0 <= Float64(-Inf))
		tmp = Float64(D_m * Float64(sqrt(Float64(Float64(M_m * Float64(Float64(-0.25 * Float64(h * Float64(M_m / d_m))) / l)) / d_m)) * w0));
	elseif (t_0 <= 2e-6)
		tmp = Float64(w0 * sqrt(Float64(1.0 - Float64(Float64(h / l) / Float64(4.0 * Float64(t_1 * t_1))))));
	else
		tmp = Float64(w0 * sqrt(Float64(1.0 - Float64(Float64(Float64(D_m * Float64(h * M_m)) * Float64(Float64(D_m * Float64(M_m / d_m)) * Float64(0.25 / d_m))) / l))));
	end
	return tmp
end
M_m = abs(M);
D_m = abs(D);
d_m = abs(d);
w0, M_m, D_m, h, l, d_m = num2cell(sort([w0, M_m, D_m, h, l, d_m])){:}
function tmp_2 = code(w0, M_m, D_m, h, l, d_m)
	t_0 = (((M_m * D_m) / (2.0 * d_m)) ^ 2.0) * (h / l);
	t_1 = d_m / (D_m * M_m);
	tmp = 0.0;
	if (t_0 <= -Inf)
		tmp = D_m * (sqrt(((M_m * ((-0.25 * (h * (M_m / d_m))) / l)) / d_m)) * w0);
	elseif (t_0 <= 2e-6)
		tmp = w0 * sqrt((1.0 - ((h / l) / (4.0 * (t_1 * t_1)))));
	else
		tmp = w0 * sqrt((1.0 - (((D_m * (h * M_m)) * ((D_m * (M_m / d_m)) * (0.25 / d_m))) / l)));
	end
	tmp_2 = tmp;
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
d_m = N[Abs[d], $MachinePrecision]
NOTE: w0, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
code[w0_, M$95$m_, D$95$m_, h_, l_, d$95$m_] := Block[{t$95$0 = N[(N[Power[N[(N[(M$95$m * D$95$m), $MachinePrecision] / N[(2.0 * d$95$m), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(d$95$m / N[(D$95$m * M$95$m), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], N[(D$95$m * N[(N[Sqrt[N[(N[(M$95$m * N[(N[(-0.25 * N[(h * N[(M$95$m / d$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision] / d$95$m), $MachinePrecision]], $MachinePrecision] * w0), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 2e-6], N[(w0 * N[Sqrt[N[(1.0 - N[(N[(h / l), $MachinePrecision] / N[(4.0 * N[(t$95$1 * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(w0 * N[Sqrt[N[(1.0 - N[(N[(N[(D$95$m * N[(h * M$95$m), $MachinePrecision]), $MachinePrecision] * N[(N[(D$95$m * N[(M$95$m / d$95$m), $MachinePrecision]), $MachinePrecision] * N[(0.25 / d$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
d_m = \left|d\right|
\\
[w0, M_m, D_m, h, l, d_m] = \mathsf{sort}([w0, M_m, D_m, h, l, d_m])\\
\\
\begin{array}{l}
t_0 := {\left(\frac{M\_m \cdot D\_m}{2 \cdot d\_m}\right)}^{2} \cdot \frac{h}{\ell}\\
t_1 := \frac{d\_m}{D\_m \cdot M\_m}\\
\mathbf{if}\;t\_0 \leq -\infty:\\
\;\;\;\;D\_m \cdot \left(\sqrt{\frac{M\_m \cdot \frac{-0.25 \cdot \left(h \cdot \frac{M\_m}{d\_m}\right)}{\ell}}{d\_m}} \cdot w0\right)\\

\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{-6}:\\
\;\;\;\;w0 \cdot \sqrt{1 - \frac{\frac{h}{\ell}}{4 \cdot \left(t\_1 \cdot t\_1\right)}}\\

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


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

    1. Initial program 49.6%

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

      \[\leadsto expr\]
    3. Add Preprocessing
    4. Taylor expanded in h around inf 0

      \[\leadsto expr\]
    5. Simplified0

      \[\leadsto expr\]
    6. Applied egg-rr0

      \[\leadsto expr\]
    7. Applied egg-rr0

      \[\leadsto expr\]
    8. Taylor expanded in M around 0 0

      \[\leadsto expr\]
    9. Simplified0

      \[\leadsto expr\]

    if -inf.0 < (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) #s(literal 2 binary64)) (/.f64 h l)) < 1.99999999999999991e-6

    1. Initial program 99.9%

      \[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]
    2. Add Preprocessing
    3. Applied egg-rr0

      \[\leadsto expr\]

    if 1.99999999999999991e-6 < (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) #s(literal 2 binary64)) (/.f64 h l))

    1. Initial program 0.0%

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

      \[\leadsto expr\]
    3. Add Preprocessing
    4. Applied egg-rr0

      \[\leadsto expr\]
    5. Applied egg-rr0

      \[\leadsto expr\]
    6. Applied egg-rr0

      \[\leadsto expr\]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 3: 84.7% accurate, 1.7× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ d_m = \left|d\right| \\ [w0, M_m, D_m, h, l, d_m] = \mathsf{sort}([w0, M_m, D_m, h, l, d_m])\\ \\ \begin{array}{l} \mathbf{if}\;\frac{h}{\ell} \leq -1 \cdot 10^{-255}:\\ \;\;\;\;w0 \cdot \sqrt{1 + \frac{h \cdot \frac{\frac{\frac{D\_m}{\frac{d\_m}{D\_m \cdot M\_m}} \cdot M\_m}{d\_m}}{-4}}{\ell}}\\ \mathbf{else}:\\ \;\;\;\;w0\\ \end{array} \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
d_m = (fabs.f64 d)
NOTE: w0, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
(FPCore (w0 M_m D_m h l d_m)
 :precision binary64
 (if (<= (/ h l) -1e-255)
   (*
    w0
    (sqrt
     (+ 1.0 (/ (* h (/ (/ (* (/ D_m (/ d_m (* D_m M_m))) M_m) d_m) -4.0)) l))))
   w0))
M_m = fabs(M);
D_m = fabs(D);
d_m = fabs(d);
assert(w0 < M_m && M_m < D_m && D_m < h && h < l && l < d_m);
double code(double w0, double M_m, double D_m, double h, double l, double d_m) {
	double tmp;
	if ((h / l) <= -1e-255) {
		tmp = w0 * sqrt((1.0 + ((h * ((((D_m / (d_m / (D_m * M_m))) * M_m) / d_m) / -4.0)) / l)));
	} else {
		tmp = w0;
	}
	return tmp;
}
M_m = abs(m)
D_m = abs(d)
d_m = abs(d)
NOTE: w0, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
real(8) function code(w0, m_m, d_m, h, l, d_m_1)
    real(8), intent (in) :: w0
    real(8), intent (in) :: m_m
    real(8), intent (in) :: d_m
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: d_m_1
    real(8) :: tmp
    if ((h / l) <= (-1d-255)) then
        tmp = w0 * sqrt((1.0d0 + ((h * ((((d_m / (d_m_1 / (d_m * m_m))) * m_m) / d_m_1) / (-4.0d0))) / l)))
    else
        tmp = w0
    end if
    code = tmp
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
d_m = Math.abs(d);
assert w0 < M_m && M_m < D_m && D_m < h && h < l && l < d_m;
public static double code(double w0, double M_m, double D_m, double h, double l, double d_m) {
	double tmp;
	if ((h / l) <= -1e-255) {
		tmp = w0 * Math.sqrt((1.0 + ((h * ((((D_m / (d_m / (D_m * M_m))) * M_m) / d_m) / -4.0)) / l)));
	} else {
		tmp = w0;
	}
	return tmp;
}
M_m = math.fabs(M)
D_m = math.fabs(D)
d_m = math.fabs(d)
[w0, M_m, D_m, h, l, d_m] = sort([w0, M_m, D_m, h, l, d_m])
def code(w0, M_m, D_m, h, l, d_m):
	tmp = 0
	if (h / l) <= -1e-255:
		tmp = w0 * math.sqrt((1.0 + ((h * ((((D_m / (d_m / (D_m * M_m))) * M_m) / d_m) / -4.0)) / l)))
	else:
		tmp = w0
	return tmp
M_m = abs(M)
D_m = abs(D)
d_m = abs(d)
w0, M_m, D_m, h, l, d_m = sort([w0, M_m, D_m, h, l, d_m])
function code(w0, M_m, D_m, h, l, d_m)
	tmp = 0.0
	if (Float64(h / l) <= -1e-255)
		tmp = Float64(w0 * sqrt(Float64(1.0 + Float64(Float64(h * Float64(Float64(Float64(Float64(D_m / Float64(d_m / Float64(D_m * M_m))) * M_m) / d_m) / -4.0)) / l))));
	else
		tmp = w0;
	end
	return tmp
end
M_m = abs(M);
D_m = abs(D);
d_m = abs(d);
w0, M_m, D_m, h, l, d_m = num2cell(sort([w0, M_m, D_m, h, l, d_m])){:}
function tmp_2 = code(w0, M_m, D_m, h, l, d_m)
	tmp = 0.0;
	if ((h / l) <= -1e-255)
		tmp = w0 * sqrt((1.0 + ((h * ((((D_m / (d_m / (D_m * M_m))) * M_m) / d_m) / -4.0)) / l)));
	else
		tmp = w0;
	end
	tmp_2 = tmp;
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
d_m = N[Abs[d], $MachinePrecision]
NOTE: w0, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
code[w0_, M$95$m_, D$95$m_, h_, l_, d$95$m_] := If[LessEqual[N[(h / l), $MachinePrecision], -1e-255], N[(w0 * N[Sqrt[N[(1.0 + N[(N[(h * N[(N[(N[(N[(D$95$m / N[(d$95$m / N[(D$95$m * M$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * M$95$m), $MachinePrecision] / d$95$m), $MachinePrecision] / -4.0), $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], w0]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
d_m = \left|d\right|
\\
[w0, M_m, D_m, h, l, d_m] = \mathsf{sort}([w0, M_m, D_m, h, l, d_m])\\
\\
\begin{array}{l}
\mathbf{if}\;\frac{h}{\ell} \leq -1 \cdot 10^{-255}:\\
\;\;\;\;w0 \cdot \sqrt{1 + \frac{h \cdot \frac{\frac{\frac{D\_m}{\frac{d\_m}{D\_m \cdot M\_m}} \cdot M\_m}{d\_m}}{-4}}{\ell}}\\

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


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

    1. Initial program 77.5%

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

      \[\leadsto expr\]
    3. Add Preprocessing
    4. Applied egg-rr0

      \[\leadsto expr\]

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

    1. Initial program 89.1%

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

      \[\leadsto expr\]
    4. Simplified0

      \[\leadsto expr\]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 4: 84.9% accurate, 1.7× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ d_m = \left|d\right| \\ [w0, M_m, D_m, h, l, d_m] = \mathsf{sort}([w0, M_m, D_m, h, l, d_m])\\ \\ \begin{array}{l} \mathbf{if}\;\frac{h}{\ell} \leq -1 \cdot 10^{-255}:\\ \;\;\;\;w0 \cdot \sqrt{1 + \frac{\frac{M\_m}{d\_m} \cdot \frac{D\_m}{\frac{d\_m}{D\_m \cdot M\_m}}}{\ell \cdot -4} \cdot h}\\ \mathbf{else}:\\ \;\;\;\;w0\\ \end{array} \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
d_m = (fabs.f64 d)
NOTE: w0, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
(FPCore (w0 M_m D_m h l d_m)
 :precision binary64
 (if (<= (/ h l) -1e-255)
   (*
    w0
    (sqrt
     (+ 1.0 (* (/ (* (/ M_m d_m) (/ D_m (/ d_m (* D_m M_m)))) (* l -4.0)) h))))
   w0))
M_m = fabs(M);
D_m = fabs(D);
d_m = fabs(d);
assert(w0 < M_m && M_m < D_m && D_m < h && h < l && l < d_m);
double code(double w0, double M_m, double D_m, double h, double l, double d_m) {
	double tmp;
	if ((h / l) <= -1e-255) {
		tmp = w0 * sqrt((1.0 + ((((M_m / d_m) * (D_m / (d_m / (D_m * M_m)))) / (l * -4.0)) * h)));
	} else {
		tmp = w0;
	}
	return tmp;
}
M_m = abs(m)
D_m = abs(d)
d_m = abs(d)
NOTE: w0, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
real(8) function code(w0, m_m, d_m, h, l, d_m_1)
    real(8), intent (in) :: w0
    real(8), intent (in) :: m_m
    real(8), intent (in) :: d_m
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: d_m_1
    real(8) :: tmp
    if ((h / l) <= (-1d-255)) then
        tmp = w0 * sqrt((1.0d0 + ((((m_m / d_m_1) * (d_m / (d_m_1 / (d_m * m_m)))) / (l * (-4.0d0))) * h)))
    else
        tmp = w0
    end if
    code = tmp
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
d_m = Math.abs(d);
assert w0 < M_m && M_m < D_m && D_m < h && h < l && l < d_m;
public static double code(double w0, double M_m, double D_m, double h, double l, double d_m) {
	double tmp;
	if ((h / l) <= -1e-255) {
		tmp = w0 * Math.sqrt((1.0 + ((((M_m / d_m) * (D_m / (d_m / (D_m * M_m)))) / (l * -4.0)) * h)));
	} else {
		tmp = w0;
	}
	return tmp;
}
M_m = math.fabs(M)
D_m = math.fabs(D)
d_m = math.fabs(d)
[w0, M_m, D_m, h, l, d_m] = sort([w0, M_m, D_m, h, l, d_m])
def code(w0, M_m, D_m, h, l, d_m):
	tmp = 0
	if (h / l) <= -1e-255:
		tmp = w0 * math.sqrt((1.0 + ((((M_m / d_m) * (D_m / (d_m / (D_m * M_m)))) / (l * -4.0)) * h)))
	else:
		tmp = w0
	return tmp
M_m = abs(M)
D_m = abs(D)
d_m = abs(d)
w0, M_m, D_m, h, l, d_m = sort([w0, M_m, D_m, h, l, d_m])
function code(w0, M_m, D_m, h, l, d_m)
	tmp = 0.0
	if (Float64(h / l) <= -1e-255)
		tmp = Float64(w0 * sqrt(Float64(1.0 + Float64(Float64(Float64(Float64(M_m / d_m) * Float64(D_m / Float64(d_m / Float64(D_m * M_m)))) / Float64(l * -4.0)) * h))));
	else
		tmp = w0;
	end
	return tmp
end
M_m = abs(M);
D_m = abs(D);
d_m = abs(d);
w0, M_m, D_m, h, l, d_m = num2cell(sort([w0, M_m, D_m, h, l, d_m])){:}
function tmp_2 = code(w0, M_m, D_m, h, l, d_m)
	tmp = 0.0;
	if ((h / l) <= -1e-255)
		tmp = w0 * sqrt((1.0 + ((((M_m / d_m) * (D_m / (d_m / (D_m * M_m)))) / (l * -4.0)) * h)));
	else
		tmp = w0;
	end
	tmp_2 = tmp;
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
d_m = N[Abs[d], $MachinePrecision]
NOTE: w0, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
code[w0_, M$95$m_, D$95$m_, h_, l_, d$95$m_] := If[LessEqual[N[(h / l), $MachinePrecision], -1e-255], N[(w0 * N[Sqrt[N[(1.0 + N[(N[(N[(N[(M$95$m / d$95$m), $MachinePrecision] * N[(D$95$m / N[(d$95$m / N[(D$95$m * M$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(l * -4.0), $MachinePrecision]), $MachinePrecision] * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], w0]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
d_m = \left|d\right|
\\
[w0, M_m, D_m, h, l, d_m] = \mathsf{sort}([w0, M_m, D_m, h, l, d_m])\\
\\
\begin{array}{l}
\mathbf{if}\;\frac{h}{\ell} \leq -1 \cdot 10^{-255}:\\
\;\;\;\;w0 \cdot \sqrt{1 + \frac{\frac{M\_m}{d\_m} \cdot \frac{D\_m}{\frac{d\_m}{D\_m \cdot M\_m}}}{\ell \cdot -4} \cdot h}\\

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


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

    1. Initial program 77.5%

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

      \[\leadsto expr\]
    3. Add Preprocessing
    4. Applied egg-rr0

      \[\leadsto expr\]

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

    1. Initial program 89.1%

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

      \[\leadsto expr\]
    4. Simplified0

      \[\leadsto expr\]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 5: 86.6% accurate, 1.7× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ d_m = \left|d\right| \\ [w0, M_m, D_m, h, l, d_m] = \mathsf{sort}([w0, M_m, D_m, h, l, d_m])\\ \\ \begin{array}{l} t_0 := D\_m \cdot \frac{M\_m}{d\_m}\\ \mathbf{if}\;d\_m \leq 10^{+18}:\\ \;\;\;\;w0 \cdot \sqrt{1 + \frac{\frac{h}{\frac{-4}{t\_0 \cdot t\_0}}}{\ell}}\\ \mathbf{else}:\\ \;\;\;\;w0 \cdot \sqrt{1 - \frac{\left(M\_m \cdot h\right) \cdot \left(\frac{\frac{D\_m}{d\_m}}{4} \cdot t\_0\right)}{\ell}}\\ \end{array} \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
d_m = (fabs.f64 d)
NOTE: w0, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
(FPCore (w0 M_m D_m h l d_m)
 :precision binary64
 (let* ((t_0 (* D_m (/ M_m d_m))))
   (if (<= d_m 1e+18)
     (* w0 (sqrt (+ 1.0 (/ (/ h (/ -4.0 (* t_0 t_0))) l))))
     (* w0 (sqrt (- 1.0 (/ (* (* M_m h) (* (/ (/ D_m d_m) 4.0) t_0)) l)))))))
M_m = fabs(M);
D_m = fabs(D);
d_m = fabs(d);
assert(w0 < M_m && M_m < D_m && D_m < h && h < l && l < d_m);
double code(double w0, double M_m, double D_m, double h, double l, double d_m) {
	double t_0 = D_m * (M_m / d_m);
	double tmp;
	if (d_m <= 1e+18) {
		tmp = w0 * sqrt((1.0 + ((h / (-4.0 / (t_0 * t_0))) / l)));
	} else {
		tmp = w0 * sqrt((1.0 - (((M_m * h) * (((D_m / d_m) / 4.0) * t_0)) / l)));
	}
	return tmp;
}
M_m = abs(m)
D_m = abs(d)
d_m = abs(d)
NOTE: w0, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
real(8) function code(w0, m_m, d_m, h, l, d_m_1)
    real(8), intent (in) :: w0
    real(8), intent (in) :: m_m
    real(8), intent (in) :: d_m
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: d_m_1
    real(8) :: t_0
    real(8) :: tmp
    t_0 = d_m * (m_m / d_m_1)
    if (d_m_1 <= 1d+18) then
        tmp = w0 * sqrt((1.0d0 + ((h / ((-4.0d0) / (t_0 * t_0))) / l)))
    else
        tmp = w0 * sqrt((1.0d0 - (((m_m * h) * (((d_m / d_m_1) / 4.0d0) * t_0)) / l)))
    end if
    code = tmp
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
d_m = Math.abs(d);
assert w0 < M_m && M_m < D_m && D_m < h && h < l && l < d_m;
public static double code(double w0, double M_m, double D_m, double h, double l, double d_m) {
	double t_0 = D_m * (M_m / d_m);
	double tmp;
	if (d_m <= 1e+18) {
		tmp = w0 * Math.sqrt((1.0 + ((h / (-4.0 / (t_0 * t_0))) / l)));
	} else {
		tmp = w0 * Math.sqrt((1.0 - (((M_m * h) * (((D_m / d_m) / 4.0) * t_0)) / l)));
	}
	return tmp;
}
M_m = math.fabs(M)
D_m = math.fabs(D)
d_m = math.fabs(d)
[w0, M_m, D_m, h, l, d_m] = sort([w0, M_m, D_m, h, l, d_m])
def code(w0, M_m, D_m, h, l, d_m):
	t_0 = D_m * (M_m / d_m)
	tmp = 0
	if d_m <= 1e+18:
		tmp = w0 * math.sqrt((1.0 + ((h / (-4.0 / (t_0 * t_0))) / l)))
	else:
		tmp = w0 * math.sqrt((1.0 - (((M_m * h) * (((D_m / d_m) / 4.0) * t_0)) / l)))
	return tmp
M_m = abs(M)
D_m = abs(D)
d_m = abs(d)
w0, M_m, D_m, h, l, d_m = sort([w0, M_m, D_m, h, l, d_m])
function code(w0, M_m, D_m, h, l, d_m)
	t_0 = Float64(D_m * Float64(M_m / d_m))
	tmp = 0.0
	if (d_m <= 1e+18)
		tmp = Float64(w0 * sqrt(Float64(1.0 + Float64(Float64(h / Float64(-4.0 / Float64(t_0 * t_0))) / l))));
	else
		tmp = Float64(w0 * sqrt(Float64(1.0 - Float64(Float64(Float64(M_m * h) * Float64(Float64(Float64(D_m / d_m) / 4.0) * t_0)) / l))));
	end
	return tmp
end
M_m = abs(M);
D_m = abs(D);
d_m = abs(d);
w0, M_m, D_m, h, l, d_m = num2cell(sort([w0, M_m, D_m, h, l, d_m])){:}
function tmp_2 = code(w0, M_m, D_m, h, l, d_m)
	t_0 = D_m * (M_m / d_m);
	tmp = 0.0;
	if (d_m <= 1e+18)
		tmp = w0 * sqrt((1.0 + ((h / (-4.0 / (t_0 * t_0))) / l)));
	else
		tmp = w0 * sqrt((1.0 - (((M_m * h) * (((D_m / d_m) / 4.0) * t_0)) / l)));
	end
	tmp_2 = tmp;
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
d_m = N[Abs[d], $MachinePrecision]
NOTE: w0, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
code[w0_, M$95$m_, D$95$m_, h_, l_, d$95$m_] := Block[{t$95$0 = N[(D$95$m * N[(M$95$m / d$95$m), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d$95$m, 1e+18], N[(w0 * N[Sqrt[N[(1.0 + N[(N[(h / N[(-4.0 / N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(w0 * N[Sqrt[N[(1.0 - N[(N[(N[(M$95$m * h), $MachinePrecision] * N[(N[(N[(D$95$m / d$95$m), $MachinePrecision] / 4.0), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
d_m = \left|d\right|
\\
[w0, M_m, D_m, h, l, d_m] = \mathsf{sort}([w0, M_m, D_m, h, l, d_m])\\
\\
\begin{array}{l}
t_0 := D\_m \cdot \frac{M\_m}{d\_m}\\
\mathbf{if}\;d\_m \leq 10^{+18}:\\
\;\;\;\;w0 \cdot \sqrt{1 + \frac{\frac{h}{\frac{-4}{t\_0 \cdot t\_0}}}{\ell}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < 1e18

    1. Initial program 85.7%

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

      \[\leadsto expr\]
    3. Add Preprocessing
    4. Applied egg-rr0

      \[\leadsto expr\]
    5. Applied egg-rr0

      \[\leadsto expr\]

    if 1e18 < d

    1. Initial program 75.7%

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

      \[\leadsto expr\]
    3. Add Preprocessing
    4. Applied egg-rr0

      \[\leadsto expr\]
    5. Applied egg-rr0

      \[\leadsto expr\]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 6: 86.5% accurate, 1.8× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ d_m = \left|d\right| \\ [w0, M_m, D_m, h, l, d_m] = \mathsf{sort}([w0, M_m, D_m, h, l, d_m])\\ \\ \begin{array}{l} t_0 := D\_m \cdot \frac{M\_m}{d\_m}\\ w0 \cdot \sqrt{1 + \frac{\frac{h}{\frac{-4}{t\_0 \cdot t\_0}}}{\ell}} \end{array} \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
d_m = (fabs.f64 d)
NOTE: w0, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
(FPCore (w0 M_m D_m h l d_m)
 :precision binary64
 (let* ((t_0 (* D_m (/ M_m d_m))))
   (* w0 (sqrt (+ 1.0 (/ (/ h (/ -4.0 (* t_0 t_0))) l))))))
M_m = fabs(M);
D_m = fabs(D);
d_m = fabs(d);
assert(w0 < M_m && M_m < D_m && D_m < h && h < l && l < d_m);
double code(double w0, double M_m, double D_m, double h, double l, double d_m) {
	double t_0 = D_m * (M_m / d_m);
	return w0 * sqrt((1.0 + ((h / (-4.0 / (t_0 * t_0))) / l)));
}
M_m = abs(m)
D_m = abs(d)
d_m = abs(d)
NOTE: w0, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
real(8) function code(w0, m_m, d_m, h, l, d_m_1)
    real(8), intent (in) :: w0
    real(8), intent (in) :: m_m
    real(8), intent (in) :: d_m
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: d_m_1
    real(8) :: t_0
    t_0 = d_m * (m_m / d_m_1)
    code = w0 * sqrt((1.0d0 + ((h / ((-4.0d0) / (t_0 * t_0))) / l)))
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
d_m = Math.abs(d);
assert w0 < M_m && M_m < D_m && D_m < h && h < l && l < d_m;
public static double code(double w0, double M_m, double D_m, double h, double l, double d_m) {
	double t_0 = D_m * (M_m / d_m);
	return w0 * Math.sqrt((1.0 + ((h / (-4.0 / (t_0 * t_0))) / l)));
}
M_m = math.fabs(M)
D_m = math.fabs(D)
d_m = math.fabs(d)
[w0, M_m, D_m, h, l, d_m] = sort([w0, M_m, D_m, h, l, d_m])
def code(w0, M_m, D_m, h, l, d_m):
	t_0 = D_m * (M_m / d_m)
	return w0 * math.sqrt((1.0 + ((h / (-4.0 / (t_0 * t_0))) / l)))
M_m = abs(M)
D_m = abs(D)
d_m = abs(d)
w0, M_m, D_m, h, l, d_m = sort([w0, M_m, D_m, h, l, d_m])
function code(w0, M_m, D_m, h, l, d_m)
	t_0 = Float64(D_m * Float64(M_m / d_m))
	return Float64(w0 * sqrt(Float64(1.0 + Float64(Float64(h / Float64(-4.0 / Float64(t_0 * t_0))) / l))))
end
M_m = abs(M);
D_m = abs(D);
d_m = abs(d);
w0, M_m, D_m, h, l, d_m = num2cell(sort([w0, M_m, D_m, h, l, d_m])){:}
function tmp = code(w0, M_m, D_m, h, l, d_m)
	t_0 = D_m * (M_m / d_m);
	tmp = w0 * sqrt((1.0 + ((h / (-4.0 / (t_0 * t_0))) / l)));
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
d_m = N[Abs[d], $MachinePrecision]
NOTE: w0, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
code[w0_, M$95$m_, D$95$m_, h_, l_, d$95$m_] := Block[{t$95$0 = N[(D$95$m * N[(M$95$m / d$95$m), $MachinePrecision]), $MachinePrecision]}, N[(w0 * N[Sqrt[N[(1.0 + N[(N[(h / N[(-4.0 / N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
d_m = \left|d\right|
\\
[w0, M_m, D_m, h, l, d_m] = \mathsf{sort}([w0, M_m, D_m, h, l, d_m])\\
\\
\begin{array}{l}
t_0 := D\_m \cdot \frac{M\_m}{d\_m}\\
w0 \cdot \sqrt{1 + \frac{\frac{h}{\frac{-4}{t\_0 \cdot t\_0}}}{\ell}}
\end{array}
\end{array}
Derivation
  1. Initial program 82.9%

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

    \[\leadsto expr\]
  3. Add Preprocessing
  4. Applied egg-rr0

    \[\leadsto expr\]
  5. Applied egg-rr0

    \[\leadsto expr\]
  6. Add Preprocessing

Alternative 7: 77.5% accurate, 8.3× speedup?

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

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


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

    1. Initial program 84.9%

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

      \[\leadsto expr\]
    3. Add Preprocessing
    4. Applied egg-rr0

      \[\leadsto expr\]
    5. Taylor expanded in h around 0 0

      \[\leadsto expr\]
    6. Simplified0

      \[\leadsto expr\]
    7. Applied egg-rr0

      \[\leadsto expr\]

    if 1.91999999999999992e-76 < d

    1. Initial program 78.9%

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

      \[\leadsto expr\]
    3. Add Preprocessing
    4. Applied egg-rr0

      \[\leadsto expr\]
    5. Taylor expanded in h around 0 0

      \[\leadsto expr\]
    6. Simplified0

      \[\leadsto expr\]
    7. Applied egg-rr0

      \[\leadsto expr\]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 8: 74.7% accurate, 8.3× speedup?

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

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


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

    1. Initial program 84.9%

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

      \[\leadsto expr\]
    3. Add Preprocessing
    4. Applied egg-rr0

      \[\leadsto expr\]
    5. Taylor expanded in h around 0 0

      \[\leadsto expr\]
    6. Simplified0

      \[\leadsto expr\]
    7. Applied egg-rr0

      \[\leadsto expr\]

    if 3.80000000000000011e-88 < d

    1. Initial program 79.2%

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

      \[\leadsto expr\]
    4. Simplified0

      \[\leadsto expr\]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 9: 70.1% accurate, 9.0× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ d_m = \left|d\right| \\ [w0, M_m, D_m, h, l, d_m] = \mathsf{sort}([w0, M_m, D_m, h, l, d_m])\\ \\ \begin{array}{l} \mathbf{if}\;M\_m \leq 1.05 \cdot 10^{+154}:\\ \;\;\;\;w0\\ \mathbf{else}:\\ \;\;\;\;w0 \cdot \left(\left(\frac{h \cdot \frac{M\_m \cdot M\_m}{d\_m}}{\frac{\ell}{-0.125}} \cdot D\_m\right) \cdot \frac{D\_m}{d\_m}\right)\\ \end{array} \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
d_m = (fabs.f64 d)
NOTE: w0, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
(FPCore (w0 M_m D_m h l d_m)
 :precision binary64
 (if (<= M_m 1.05e+154)
   w0
   (* w0 (* (* (/ (* h (/ (* M_m M_m) d_m)) (/ l -0.125)) D_m) (/ D_m d_m)))))
M_m = fabs(M);
D_m = fabs(D);
d_m = fabs(d);
assert(w0 < M_m && M_m < D_m && D_m < h && h < l && l < d_m);
double code(double w0, double M_m, double D_m, double h, double l, double d_m) {
	double tmp;
	if (M_m <= 1.05e+154) {
		tmp = w0;
	} else {
		tmp = w0 * ((((h * ((M_m * M_m) / d_m)) / (l / -0.125)) * D_m) * (D_m / d_m));
	}
	return tmp;
}
M_m = abs(m)
D_m = abs(d)
d_m = abs(d)
NOTE: w0, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
real(8) function code(w0, m_m, d_m, h, l, d_m_1)
    real(8), intent (in) :: w0
    real(8), intent (in) :: m_m
    real(8), intent (in) :: d_m
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: d_m_1
    real(8) :: tmp
    if (m_m <= 1.05d+154) then
        tmp = w0
    else
        tmp = w0 * ((((h * ((m_m * m_m) / d_m_1)) / (l / (-0.125d0))) * d_m) * (d_m / d_m_1))
    end if
    code = tmp
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
d_m = Math.abs(d);
assert w0 < M_m && M_m < D_m && D_m < h && h < l && l < d_m;
public static double code(double w0, double M_m, double D_m, double h, double l, double d_m) {
	double tmp;
	if (M_m <= 1.05e+154) {
		tmp = w0;
	} else {
		tmp = w0 * ((((h * ((M_m * M_m) / d_m)) / (l / -0.125)) * D_m) * (D_m / d_m));
	}
	return tmp;
}
M_m = math.fabs(M)
D_m = math.fabs(D)
d_m = math.fabs(d)
[w0, M_m, D_m, h, l, d_m] = sort([w0, M_m, D_m, h, l, d_m])
def code(w0, M_m, D_m, h, l, d_m):
	tmp = 0
	if M_m <= 1.05e+154:
		tmp = w0
	else:
		tmp = w0 * ((((h * ((M_m * M_m) / d_m)) / (l / -0.125)) * D_m) * (D_m / d_m))
	return tmp
M_m = abs(M)
D_m = abs(D)
d_m = abs(d)
w0, M_m, D_m, h, l, d_m = sort([w0, M_m, D_m, h, l, d_m])
function code(w0, M_m, D_m, h, l, d_m)
	tmp = 0.0
	if (M_m <= 1.05e+154)
		tmp = w0;
	else
		tmp = Float64(w0 * Float64(Float64(Float64(Float64(h * Float64(Float64(M_m * M_m) / d_m)) / Float64(l / -0.125)) * D_m) * Float64(D_m / d_m)));
	end
	return tmp
end
M_m = abs(M);
D_m = abs(D);
d_m = abs(d);
w0, M_m, D_m, h, l, d_m = num2cell(sort([w0, M_m, D_m, h, l, d_m])){:}
function tmp_2 = code(w0, M_m, D_m, h, l, d_m)
	tmp = 0.0;
	if (M_m <= 1.05e+154)
		tmp = w0;
	else
		tmp = w0 * ((((h * ((M_m * M_m) / d_m)) / (l / -0.125)) * D_m) * (D_m / d_m));
	end
	tmp_2 = tmp;
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
d_m = N[Abs[d], $MachinePrecision]
NOTE: w0, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
code[w0_, M$95$m_, D$95$m_, h_, l_, d$95$m_] := If[LessEqual[M$95$m, 1.05e+154], w0, N[(w0 * N[(N[(N[(N[(h * N[(N[(M$95$m * M$95$m), $MachinePrecision] / d$95$m), $MachinePrecision]), $MachinePrecision] / N[(l / -0.125), $MachinePrecision]), $MachinePrecision] * D$95$m), $MachinePrecision] * N[(D$95$m / d$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
d_m = \left|d\right|
\\
[w0, M_m, D_m, h, l, d_m] = \mathsf{sort}([w0, M_m, D_m, h, l, d_m])\\
\\
\begin{array}{l}
\mathbf{if}\;M\_m \leq 1.05 \cdot 10^{+154}:\\
\;\;\;\;w0\\

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


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

    1. Initial program 84.3%

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

      \[\leadsto expr\]
    4. Simplified0

      \[\leadsto expr\]

    if 1.04999999999999997e154 < M

    1. Initial program 70.4%

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

      \[\leadsto expr\]
    3. Add Preprocessing
    4. Applied egg-rr0

      \[\leadsto expr\]
    5. Taylor expanded in h around 0 0

      \[\leadsto expr\]
    6. Simplified0

      \[\leadsto expr\]
    7. Taylor expanded in D around inf 0

      \[\leadsto expr\]
    8. Simplified0

      \[\leadsto expr\]
    9. Applied egg-rr0

      \[\leadsto expr\]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 10: 67.7% accurate, 216.0× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ d_m = \left|d\right| \\ [w0, M_m, D_m, h, l, d_m] = \mathsf{sort}([w0, M_m, D_m, h, l, d_m])\\ \\ w0 \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
d_m = (fabs.f64 d)
NOTE: w0, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
(FPCore (w0 M_m D_m h l d_m) :precision binary64 w0)
M_m = fabs(M);
D_m = fabs(D);
d_m = fabs(d);
assert(w0 < M_m && M_m < D_m && D_m < h && h < l && l < d_m);
double code(double w0, double M_m, double D_m, double h, double l, double d_m) {
	return w0;
}
M_m = abs(m)
D_m = abs(d)
d_m = abs(d)
NOTE: w0, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
real(8) function code(w0, m_m, d_m, h, l, d_m_1)
    real(8), intent (in) :: w0
    real(8), intent (in) :: m_m
    real(8), intent (in) :: d_m
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: d_m_1
    code = w0
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
d_m = Math.abs(d);
assert w0 < M_m && M_m < D_m && D_m < h && h < l && l < d_m;
public static double code(double w0, double M_m, double D_m, double h, double l, double d_m) {
	return w0;
}
M_m = math.fabs(M)
D_m = math.fabs(D)
d_m = math.fabs(d)
[w0, M_m, D_m, h, l, d_m] = sort([w0, M_m, D_m, h, l, d_m])
def code(w0, M_m, D_m, h, l, d_m):
	return w0
M_m = abs(M)
D_m = abs(D)
d_m = abs(d)
w0, M_m, D_m, h, l, d_m = sort([w0, M_m, D_m, h, l, d_m])
function code(w0, M_m, D_m, h, l, d_m)
	return w0
end
M_m = abs(M);
D_m = abs(D);
d_m = abs(d);
w0, M_m, D_m, h, l, d_m = num2cell(sort([w0, M_m, D_m, h, l, d_m])){:}
function tmp = code(w0, M_m, D_m, h, l, d_m)
	tmp = w0;
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
d_m = N[Abs[d], $MachinePrecision]
NOTE: w0, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
code[w0_, M$95$m_, D$95$m_, h_, l_, d$95$m_] := w0
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
d_m = \left|d\right|
\\
[w0, M_m, D_m, h, l, d_m] = \mathsf{sort}([w0, M_m, D_m, h, l, d_m])\\
\\
w0
\end{array}
Derivation
  1. Initial program 82.9%

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

    \[\leadsto expr\]
  4. Simplified0

    \[\leadsto expr\]
  5. Add Preprocessing

Reproduce

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