Henrywood and Agarwal, Equation (9a)

Percentage Accurate: 81.0% → 88.7%
Time: 18.8s
Alternatives: 5
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 5 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: 88.7% accurate, 0.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} t_0 := D\_m \cdot \frac{M\_m}{d\_m}\\ t_1 := {\left(\frac{M\_m \cdot D\_m}{2 \cdot d\_m}\right)}^{2} \cdot \frac{h}{\ell}\\ \mathbf{if}\;t\_1 \leq -\infty:\\ \;\;\;\;{\left(\sqrt[3]{w0} \cdot e^{0.16666666666666666 \cdot \left(-2 \cdot \log \left(\frac{1}{D\_m}\right) + \left(\log \left(-0.25 \cdot \left(\frac{h}{\ell} \cdot {M\_m}^{2}\right)\right) + -2 \cdot \log d\_m\right)\right)}\right)}^{3}\\ \mathbf{elif}\;t\_1 \leq 0.01:\\ \;\;\;\;w0 \cdot \sqrt{\mathsf{fma}\left(\frac{t\_0 \cdot t\_0}{4}, \frac{h}{-\ell}, 1\right)}\\ \mathbf{else}:\\ \;\;\;\;w0 \cdot \sqrt{1 + \left(1 + \left(-1 - D\_m \cdot \left(0.25 \cdot \frac{D\_m \cdot \left(h \cdot {M\_m}^{2}\right)}{\ell \cdot {d\_m}^{2}}\right)\right)\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
 (let* ((t_0 (* D_m (/ M_m d_m)))
        (t_1 (* (pow (/ (* M_m D_m) (* 2.0 d_m)) 2.0) (/ h l))))
   (if (<= t_1 (- INFINITY))
     (pow
      (*
       (cbrt w0)
       (exp
        (*
         0.16666666666666666
         (+
          (* -2.0 (log (/ 1.0 D_m)))
          (+ (log (* -0.25 (* (/ h l) (pow M_m 2.0)))) (* -2.0 (log d_m)))))))
      3.0)
     (if (<= t_1 0.01)
       (* w0 (sqrt (fma (/ (* t_0 t_0) 4.0) (/ h (- l)) 1.0)))
       (*
        w0
        (sqrt
         (+
          1.0
          (+
           1.0
           (-
            -1.0
            (*
             D_m
             (*
              0.25
              (/ (* D_m (* h (pow M_m 2.0))) (* l (pow d_m 2.0))))))))))))))
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 t_1 = pow(((M_m * D_m) / (2.0 * d_m)), 2.0) * (h / l);
	double tmp;
	if (t_1 <= -((double) INFINITY)) {
		tmp = pow((cbrt(w0) * exp((0.16666666666666666 * ((-2.0 * log((1.0 / D_m))) + (log((-0.25 * ((h / l) * pow(M_m, 2.0)))) + (-2.0 * log(d_m))))))), 3.0);
	} else if (t_1 <= 0.01) {
		tmp = w0 * sqrt(fma(((t_0 * t_0) / 4.0), (h / -l), 1.0));
	} else {
		tmp = w0 * sqrt((1.0 + (1.0 + (-1.0 - (D_m * (0.25 * ((D_m * (h * pow(M_m, 2.0))) / (l * pow(d_m, 2.0)))))))));
	}
	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))
	t_1 = Float64((Float64(Float64(M_m * D_m) / Float64(2.0 * d_m)) ^ 2.0) * Float64(h / l))
	tmp = 0.0
	if (t_1 <= Float64(-Inf))
		tmp = Float64(cbrt(w0) * exp(Float64(0.16666666666666666 * Float64(Float64(-2.0 * log(Float64(1.0 / D_m))) + Float64(log(Float64(-0.25 * Float64(Float64(h / l) * (M_m ^ 2.0)))) + Float64(-2.0 * log(d_m))))))) ^ 3.0;
	elseif (t_1 <= 0.01)
		tmp = Float64(w0 * sqrt(fma(Float64(Float64(t_0 * t_0) / 4.0), Float64(h / Float64(-l)), 1.0)));
	else
		tmp = Float64(w0 * sqrt(Float64(1.0 + Float64(1.0 + Float64(-1.0 - Float64(D_m * Float64(0.25 * Float64(Float64(D_m * Float64(h * (M_m ^ 2.0))) / Float64(l * (d_m ^ 2.0))))))))));
	end
	return 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]}, Block[{t$95$1 = 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]}, If[LessEqual[t$95$1, (-Infinity)], N[Power[N[(N[Power[w0, 1/3], $MachinePrecision] * N[Exp[N[(0.16666666666666666 * N[(N[(-2.0 * N[Log[N[(1.0 / D$95$m), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + N[(N[Log[N[(-0.25 * N[(N[(h / l), $MachinePrecision] * N[Power[M$95$m, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + N[(-2.0 * N[Log[d$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 3.0], $MachinePrecision], If[LessEqual[t$95$1, 0.01], N[(w0 * N[Sqrt[N[(N[(N[(t$95$0 * t$95$0), $MachinePrecision] / 4.0), $MachinePrecision] * N[(h / (-l)), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(w0 * N[Sqrt[N[(1.0 + N[(1.0 + N[(-1.0 - N[(D$95$m * N[(0.25 * N[(N[(D$95$m * N[(h * N[Power[M$95$m, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(l * N[Power[d$95$m, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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}\\
t_1 := {\left(\frac{M\_m \cdot D\_m}{2 \cdot d\_m}\right)}^{2} \cdot \frac{h}{\ell}\\
\mathbf{if}\;t\_1 \leq -\infty:\\
\;\;\;\;{\left(\sqrt[3]{w0} \cdot e^{0.16666666666666666 \cdot \left(-2 \cdot \log \left(\frac{1}{D\_m}\right) + \left(\log \left(-0.25 \cdot \left(\frac{h}{\ell} \cdot {M\_m}^{2}\right)\right) + -2 \cdot \log d\_m\right)\right)}\right)}^{3}\\

\mathbf{elif}\;t\_1 \leq 0.01:\\
\;\;\;\;w0 \cdot \sqrt{\mathsf{fma}\left(\frac{t\_0 \cdot t\_0}{4}, \frac{h}{-\ell}, 1\right)}\\

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


\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 56.5%

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

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

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

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

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

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

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

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

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

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

    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 - \color{blue}{\frac{h}{\ell} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}}} \]
      2. cancel-sign-sub-inv99.9%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{w0 \cdot \sqrt{\mathsf{fma}\left({\left(\frac{D}{2} \cdot \frac{M}{d}\right)}^{2}, \frac{h}{-\ell}, 1\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. unpow298.8%

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

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

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

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

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

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

    if 0.0100000000000000002 < (*.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. Step-by-step derivation
      1. *-commutative0.0%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{w0 \cdot \sqrt{\mathsf{fma}\left({\left(\frac{D}{2} \cdot \frac{M}{d}\right)}^{2}, \frac{h}{-\ell}, 1\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. unpow23.8%

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

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

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

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

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

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

        \[\leadsto w0 \cdot \sqrt{\mathsf{fma}\left(\frac{\left(\left(D \cdot 0.5\right) \cdot M\right) \cdot \left(D \cdot \frac{M}{d}\right)}{\color{blue}{2 \cdot d}}, \frac{h}{-\ell}, 1\right)} \]
    6. Applied egg-rr0.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 87.2% accurate, 0.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}\;{\left(\frac{M\_m \cdot D\_m}{2 \cdot d\_m}\right)}^{2} \cdot \frac{h}{\ell} \leq -4 \cdot 10^{+283}:\\ \;\;\;\;{\left(\sqrt[3]{w0} \cdot e^{0.16666666666666666 \cdot \left(\left(\log \left(-0.25 \cdot \frac{\frac{h}{\ell}}{{d\_m}^{2}}\right) + 2 \cdot \log M\_m\right) + -2 \cdot \log \left(\frac{1}{D\_m}\right)\right)}\right)}^{3}\\ \mathbf{else}:\\ \;\;\;\;w0 \cdot \sqrt{1 - \frac{h \cdot {\left(D\_m \cdot \frac{M\_m}{2 \cdot d\_m}\right)}^{2}}{\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
 (if (<= (* (pow (/ (* M_m D_m) (* 2.0 d_m)) 2.0) (/ h l)) -4e+283)
   (pow
    (*
     (cbrt w0)
     (exp
      (*
       0.16666666666666666
       (+
        (+ (log (* -0.25 (/ (/ h l) (pow d_m 2.0)))) (* 2.0 (log M_m)))
        (* -2.0 (log (/ 1.0 D_m)))))))
    3.0)
   (* w0 (sqrt (- 1.0 (/ (* h (pow (* D_m (/ M_m (* 2.0 d_m))) 2.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 tmp;
	if ((pow(((M_m * D_m) / (2.0 * d_m)), 2.0) * (h / l)) <= -4e+283) {
		tmp = pow((cbrt(w0) * exp((0.16666666666666666 * ((log((-0.25 * ((h / l) / pow(d_m, 2.0)))) + (2.0 * log(M_m))) + (-2.0 * log((1.0 / D_m))))))), 3.0);
	} else {
		tmp = w0 * sqrt((1.0 - ((h * pow((D_m * (M_m / (2.0 * d_m))), 2.0)) / 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 tmp;
	if ((Math.pow(((M_m * D_m) / (2.0 * d_m)), 2.0) * (h / l)) <= -4e+283) {
		tmp = Math.pow((Math.cbrt(w0) * Math.exp((0.16666666666666666 * ((Math.log((-0.25 * ((h / l) / Math.pow(d_m, 2.0)))) + (2.0 * Math.log(M_m))) + (-2.0 * Math.log((1.0 / D_m))))))), 3.0);
	} else {
		tmp = w0 * Math.sqrt((1.0 - ((h * Math.pow((D_m * (M_m / (2.0 * d_m))), 2.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)
	tmp = 0.0
	if (Float64((Float64(Float64(M_m * D_m) / Float64(2.0 * d_m)) ^ 2.0) * Float64(h / l)) <= -4e+283)
		tmp = Float64(cbrt(w0) * exp(Float64(0.16666666666666666 * Float64(Float64(log(Float64(-0.25 * Float64(Float64(h / l) / (d_m ^ 2.0)))) + Float64(2.0 * log(M_m))) + Float64(-2.0 * log(Float64(1.0 / D_m))))))) ^ 3.0;
	else
		tmp = Float64(w0 * sqrt(Float64(1.0 - Float64(Float64(h * (Float64(D_m * Float64(M_m / Float64(2.0 * d_m))) ^ 2.0)) / l))));
	end
	return 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[(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], -4e+283], N[Power[N[(N[Power[w0, 1/3], $MachinePrecision] * N[Exp[N[(0.16666666666666666 * N[(N[(N[Log[N[(-0.25 * N[(N[(h / l), $MachinePrecision] / N[Power[d$95$m, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + N[(2.0 * N[Log[M$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-2.0 * N[Log[N[(1.0 / D$95$m), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 3.0], $MachinePrecision], N[(w0 * N[Sqrt[N[(1.0 - N[(N[(h * N[Power[N[(D$95$m * N[(M$95$m / N[(2.0 * d$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.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}
\mathbf{if}\;{\left(\frac{M\_m \cdot D\_m}{2 \cdot d\_m}\right)}^{2} \cdot \frac{h}{\ell} \leq -4 \cdot 10^{+283}:\\
\;\;\;\;{\left(\sqrt[3]{w0} \cdot e^{0.16666666666666666 \cdot \left(\left(\log \left(-0.25 \cdot \frac{\frac{h}{\ell}}{{d\_m}^{2}}\right) + 2 \cdot \log M\_m\right) + -2 \cdot \log \left(\frac{1}{D\_m}\right)\right)}\right)}^{3}\\

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


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

    1. Initial program 57.2%

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 86.5%

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell} \leq -4 \cdot 10^{+283}:\\ \;\;\;\;{\left(\sqrt[3]{w0} \cdot e^{0.16666666666666666 \cdot \left(\left(\log \left(-0.25 \cdot \frac{\frac{h}{\ell}}{{d}^{2}}\right) + 2 \cdot \log M\right) + -2 \cdot \log \left(\frac{1}{D}\right)\right)}\right)}^{3}\\ \mathbf{else}:\\ \;\;\;\;w0 \cdot \sqrt{1 - \frac{h \cdot {\left(D \cdot \frac{M}{2 \cdot d}\right)}^{2}}{\ell}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 85.8% 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 := D\_m \cdot \frac{M\_m}{d\_m}\\ \mathbf{if}\;1 - {\left(\frac{M\_m \cdot D\_m}{2 \cdot d\_m}\right)}^{2} \cdot \frac{h}{\ell} \leq 2 \cdot 10^{+211}:\\ \;\;\;\;w0 \cdot \sqrt{\mathsf{fma}\left(\frac{t\_0 \cdot t\_0}{4}, \frac{h}{-\ell}, 1\right)}\\ \mathbf{else}:\\ \;\;\;\;w0 \cdot \sqrt{1 + \left(1 + \left(-1 - D\_m \cdot \frac{h \cdot \left(\left(M\_m \cdot 0.5\right) \cdot \left(\left(D\_m \cdot 0.5\right) \cdot \left(M\_m \cdot {d\_m}^{-2}\right)\right)\right)}{\ell}\right)\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
 (let* ((t_0 (* D_m (/ M_m d_m))))
   (if (<= (- 1.0 (* (pow (/ (* M_m D_m) (* 2.0 d_m)) 2.0) (/ h l))) 2e+211)
     (* w0 (sqrt (fma (/ (* t_0 t_0) 4.0) (/ h (- l)) 1.0)))
     (*
      w0
      (sqrt
       (+
        1.0
        (+
         1.0
         (-
          -1.0
          (*
           D_m
           (/
            (* h (* (* M_m 0.5) (* (* D_m 0.5) (* M_m (pow d_m -2.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 ((1.0 - (pow(((M_m * D_m) / (2.0 * d_m)), 2.0) * (h / l))) <= 2e+211) {
		tmp = w0 * sqrt(fma(((t_0 * t_0) / 4.0), (h / -l), 1.0));
	} else {
		tmp = w0 * sqrt((1.0 + (1.0 + (-1.0 - (D_m * ((h * ((M_m * 0.5) * ((D_m * 0.5) * (M_m * pow(d_m, -2.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 (Float64(1.0 - Float64((Float64(Float64(M_m * D_m) / Float64(2.0 * d_m)) ^ 2.0) * Float64(h / l))) <= 2e+211)
		tmp = Float64(w0 * sqrt(fma(Float64(Float64(t_0 * t_0) / 4.0), Float64(h / Float64(-l)), 1.0)));
	else
		tmp = Float64(w0 * sqrt(Float64(1.0 + Float64(1.0 + Float64(-1.0 - Float64(D_m * Float64(Float64(h * Float64(Float64(M_m * 0.5) * Float64(Float64(D_m * 0.5) * Float64(M_m * (d_m ^ -2.0))))) / l)))))));
	end
	return 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[N[(1.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]), $MachinePrecision], 2e+211], N[(w0 * N[Sqrt[N[(N[(N[(t$95$0 * t$95$0), $MachinePrecision] / 4.0), $MachinePrecision] * N[(h / (-l)), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(w0 * N[Sqrt[N[(1.0 + N[(1.0 + N[(-1.0 - N[(D$95$m * N[(N[(h * N[(N[(M$95$m * 0.5), $MachinePrecision] * N[(N[(D$95$m * 0.5), $MachinePrecision] * N[(M$95$m * N[Power[d$95$m, -2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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}\;1 - {\left(\frac{M\_m \cdot D\_m}{2 \cdot d\_m}\right)}^{2} \cdot \frac{h}{\ell} \leq 2 \cdot 10^{+211}:\\
\;\;\;\;w0 \cdot \sqrt{\mathsf{fma}\left(\frac{t\_0 \cdot t\_0}{4}, \frac{h}{-\ell}, 1\right)}\\

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


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

    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 - \color{blue}{\frac{h}{\ell} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}}} \]
      2. cancel-sign-sub-inv99.9%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{w0 \cdot \sqrt{\mathsf{fma}\left({\left(\frac{D}{2} \cdot \frac{M}{d}\right)}^{2}, \frac{h}{-\ell}, 1\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. unpow299.4%

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

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

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

        \[\leadsto w0 \cdot \sqrt{\mathsf{fma}\left(\color{blue}{\frac{\left(D \cdot \frac{M}{d}\right) \cdot \left(D \cdot \frac{M}{d}\right)}{2 \cdot 2}}, \frac{h}{-\ell}, 1\right)} \]
      5. metadata-eval99.4%

        \[\leadsto w0 \cdot \sqrt{\mathsf{fma}\left(\frac{\left(D \cdot \frac{M}{d}\right) \cdot \left(D \cdot \frac{M}{d}\right)}{\color{blue}{4}}, \frac{h}{-\ell}, 1\right)} \]
    6. Applied egg-rr99.4%

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

    if 1.9999999999999999e211 < (-.f64 #s(literal 1 binary64) (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) #s(literal 2 binary64)) (/.f64 h l)))

    1. Initial program 41.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. *-commutative41.2%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{w0 \cdot \sqrt{\mathsf{fma}\left({\left(\frac{D}{2} \cdot \frac{M}{d}\right)}^{2}, \frac{h}{-\ell}, 1\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. unpow243.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell} \leq 2 \cdot 10^{+211}:\\ \;\;\;\;w0 \cdot \sqrt{\mathsf{fma}\left(\frac{\left(D \cdot \frac{M}{d}\right) \cdot \left(D \cdot \frac{M}{d}\right)}{4}, \frac{h}{-\ell}, 1\right)}\\ \mathbf{else}:\\ \;\;\;\;w0 \cdot \sqrt{1 + \left(1 + \left(-1 - D \cdot \frac{h \cdot \left(\left(M \cdot 0.5\right) \cdot \left(\left(D \cdot 0.5\right) \cdot \left(M \cdot {d}^{-2}\right)\right)\right)}{\ell}\right)\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 86.6% 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 + h \cdot \left(-0.25 \cdot \frac{t\_0 \cdot t\_0}{\ell}\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
 (let* ((t_0 (* D_m (/ M_m d_m))))
   (* w0 (sqrt (+ 1.0 (* h (* -0.25 (/ (* 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 * (-0.25 * ((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 * ((-0.25d0) * ((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 * (-0.25 * ((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 * (-0.25 * ((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(h * Float64(-0.25 * Float64(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 * (-0.25 * ((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[(h * N[(-0.25 * N[(N[(t$95$0 * t$95$0), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision]), $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 + h \cdot \left(-0.25 \cdot \frac{t\_0 \cdot t\_0}{\ell}\right)}
\end{array}
\end{array}
Derivation
  1. Initial program 80.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto w0 \cdot \sqrt{1 + h \cdot \left(-0.25 \cdot \frac{\left(D \cdot \frac{M}{d}\right) \cdot \left(D \cdot \frac{M}{d}\right)}{\ell}\right)} \]
  12. Add Preprocessing

Alternative 5: 67.0% 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 80.2%

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

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

    \[\leadsto \color{blue}{w0} \]
  5. Add Preprocessing

Reproduce

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