Henrywood and Agarwal, Equation (9a)

Percentage Accurate: 81.8% → 87.6%
Time: 15.2s
Alternatives: 5
Speedup: 1.0×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 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.8% accurate, 1.0× speedup?

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

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

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

\mathbf{else}:\\
\;\;\;\;{\left(\sqrt[3]{w0} \cdot {\left(e^{0.16666666666666666}\right)}^{\left(\log \left(-0.25 \cdot \frac{h \cdot {\left(M\_m \cdot D\_m\right)}^{2}}{\ell}\right) + -2 \cdot \log d\_m\right)}\right)}^{3}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) < 9.99999999999999991e131

    1. Initial program 82.2%

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

      \[\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-rr81.8%

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

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

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

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

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

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

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

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

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

    if 9.99999999999999991e131 < (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d))

    1. Initial program 52.4%

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

      \[\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-rr52.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

\mathbf{else}:\\
\;\;\;\;{\left(\sqrt[3]{w0} \cdot {\left(e^{0.16666666666666666}\right)}^{\left(-2 \cdot \log d\_m + \log \left(-0.25 \cdot \left({\left(M\_m \cdot D\_m\right)}^{2} \cdot \frac{h}{\ell}\right)\right)\right)}\right)}^{3}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) < 9.99999999999999991e131

    1. Initial program 82.2%

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

      \[\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-rr81.8%

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

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

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

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

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

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

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

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

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

    if 9.99999999999999991e131 < (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d))

    1. Initial program 52.4%

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

      \[\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-rr52.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 86.3% accurate, 1.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 \cdot \sqrt{1 - h \cdot \frac{{\left(M\_m \cdot \frac{D\_m}{2 \cdot d\_m}\right)}^{2}}{\ell}} \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 (sqrt (- 1.0 (* h (/ (pow (* M_m (/ D_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) {
	return w0 * sqrt((1.0 - (h * (pow((M_m * (D_m / (2.0 * d_m))), 2.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
    code = w0 * sqrt((1.0d0 - (h * (((m_m * (d_m / (2.0d0 * d_m_1))) ** 2.0d0) / 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) {
	return w0 * Math.sqrt((1.0 - (h * (Math.pow((M_m * (D_m / (2.0 * d_m))), 2.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):
	return w0 * math.sqrt((1.0 - (h * (math.pow((M_m * (D_m / (2.0 * d_m))), 2.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)
	return Float64(w0 * sqrt(Float64(1.0 - Float64(h * Float64((Float64(M_m * Float64(D_m / Float64(2.0 * d_m))) ^ 2.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)
	tmp = w0 * sqrt((1.0 - (h * (((M_m * (D_m / (2.0 * d_m))) ^ 2.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_] := N[(w0 * N[Sqrt[N[(1.0 - N[(h * N[(N[Power[N[(M$95$m * N[(D$95$m / N[(2.0 * d$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] / l), $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])\\
\\
w0 \cdot \sqrt{1 - h \cdot \frac{{\left(M\_m \cdot \frac{D\_m}{2 \cdot d\_m}\right)}^{2}}{\ell}}
\end{array}
Derivation
  1. Initial program 79.1%

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

    \[\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-rr78.8%

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

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

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

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

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

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

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

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

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

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

Alternative 4: 76.8% 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}\;M\_m \leq 4.2 \cdot 10^{-55}:\\ \;\;\;\;w0\\ \mathbf{else}:\\ \;\;\;\;w0 + -0.125 \cdot \left(\left(\frac{D\_m}{d\_m} \cdot \frac{D\_m}{d\_m}\right) \cdot \frac{{M\_m}^{2} \cdot \left(w0 \cdot h\right)}{\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
 (if (<= M_m 4.2e-55)
   w0
   (+
    w0
    (*
     -0.125
     (* (* (/ D_m d_m) (/ D_m d_m)) (/ (* (pow M_m 2.0) (* w0 h)) 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 (M_m <= 4.2e-55) {
		tmp = w0;
	} else {
		tmp = w0 + (-0.125 * (((D_m / d_m) * (D_m / d_m)) * ((pow(M_m, 2.0) * (w0 * h)) / 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) :: tmp
    if (m_m <= 4.2d-55) then
        tmp = w0
    else
        tmp = w0 + ((-0.125d0) * (((d_m / d_m_1) * (d_m / d_m_1)) * (((m_m ** 2.0d0) * (w0 * h)) / 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 tmp;
	if (M_m <= 4.2e-55) {
		tmp = w0;
	} else {
		tmp = w0 + (-0.125 * (((D_m / d_m) * (D_m / d_m)) * ((Math.pow(M_m, 2.0) * (w0 * h)) / 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):
	tmp = 0
	if M_m <= 4.2e-55:
		tmp = w0
	else:
		tmp = w0 + (-0.125 * (((D_m / d_m) * (D_m / d_m)) * ((math.pow(M_m, 2.0) * (w0 * h)) / 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 (M_m <= 4.2e-55)
		tmp = w0;
	else
		tmp = Float64(w0 + Float64(-0.125 * Float64(Float64(Float64(D_m / d_m) * Float64(D_m / d_m)) * Float64(Float64((M_m ^ 2.0) * Float64(w0 * h)) / 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)
	tmp = 0.0;
	if (M_m <= 4.2e-55)
		tmp = w0;
	else
		tmp = w0 + (-0.125 * (((D_m / d_m) * (D_m / d_m)) * (((M_m ^ 2.0) * (w0 * h)) / 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_] := If[LessEqual[M$95$m, 4.2e-55], w0, N[(w0 + N[(-0.125 * N[(N[(N[(D$95$m / d$95$m), $MachinePrecision] * N[(D$95$m / d$95$m), $MachinePrecision]), $MachinePrecision] * N[(N[(N[Power[M$95$m, 2.0], $MachinePrecision] * N[(w0 * h), $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}\;M\_m \leq 4.2 \cdot 10^{-55}:\\
\;\;\;\;w0\\

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


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

    1. Initial program 83.0%

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

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

    if 4.2000000000000003e-55 < M

    1. Initial program 68.2%

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

      \[\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 40.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 68.3% 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 79.1%

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

    \[\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 68.1%

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

Reproduce

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