Henrywood and Agarwal, Equation (13)

Percentage Accurate: 24.5% → 46.2%
Time: 28.7s
Alternatives: 3
Speedup: 30.2×

Specification

?
\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}\\ \frac{c0}{2 \cdot w} \cdot \left(t\_0 + \sqrt{t\_0 \cdot t\_0 - M \cdot M}\right) \end{array} \end{array} \]
(FPCore (c0 w h D d M)
 :precision binary64
 (let* ((t_0 (/ (* c0 (* d d)) (* (* w h) (* D D)))))
   (* (/ c0 (* 2.0 w)) (+ t_0 (sqrt (- (* t_0 t_0) (* M M)))))))
double code(double c0, double w, double h, double D, double d, double M) {
	double t_0 = (c0 * (d * d)) / ((w * h) * (D * D));
	return (c0 / (2.0 * w)) * (t_0 + sqrt(((t_0 * t_0) - (M * M))));
}
real(8) function code(c0, w, h, d, d_1, m)
    real(8), intent (in) :: c0
    real(8), intent (in) :: w
    real(8), intent (in) :: h
    real(8), intent (in) :: d
    real(8), intent (in) :: d_1
    real(8), intent (in) :: m
    real(8) :: t_0
    t_0 = (c0 * (d_1 * d_1)) / ((w * h) * (d * d))
    code = (c0 / (2.0d0 * w)) * (t_0 + sqrt(((t_0 * t_0) - (m * m))))
end function
public static double code(double c0, double w, double h, double D, double d, double M) {
	double t_0 = (c0 * (d * d)) / ((w * h) * (D * D));
	return (c0 / (2.0 * w)) * (t_0 + Math.sqrt(((t_0 * t_0) - (M * M))));
}
def code(c0, w, h, D, d, M):
	t_0 = (c0 * (d * d)) / ((w * h) * (D * D))
	return (c0 / (2.0 * w)) * (t_0 + math.sqrt(((t_0 * t_0) - (M * M))))
function code(c0, w, h, D, d, M)
	t_0 = Float64(Float64(c0 * Float64(d * d)) / Float64(Float64(w * h) * Float64(D * D)))
	return Float64(Float64(c0 / Float64(2.0 * w)) * Float64(t_0 + sqrt(Float64(Float64(t_0 * t_0) - Float64(M * M)))))
end
function tmp = code(c0, w, h, D, d, M)
	t_0 = (c0 * (d * d)) / ((w * h) * (D * D));
	tmp = (c0 / (2.0 * w)) * (t_0 + sqrt(((t_0 * t_0) - (M * M))));
end
code[c0_, w_, h_, D_, d_, M_] := Block[{t$95$0 = N[(N[(c0 * N[(d * d), $MachinePrecision]), $MachinePrecision] / N[(N[(w * h), $MachinePrecision] * N[(D * D), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(N[(c0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision] * N[(t$95$0 + N[Sqrt[N[(N[(t$95$0 * t$95$0), $MachinePrecision] - N[(M * M), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}\\
\frac{c0}{2 \cdot w} \cdot \left(t\_0 + \sqrt{t\_0 \cdot t\_0 - M \cdot M}\right)
\end{array}
\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 3 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: 24.5% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}\\ \frac{c0}{2 \cdot w} \cdot \left(t\_0 + \sqrt{t\_0 \cdot t\_0 - M \cdot M}\right) \end{array} \end{array} \]
(FPCore (c0 w h D d M)
 :precision binary64
 (let* ((t_0 (/ (* c0 (* d d)) (* (* w h) (* D D)))))
   (* (/ c0 (* 2.0 w)) (+ t_0 (sqrt (- (* t_0 t_0) (* M M)))))))
double code(double c0, double w, double h, double D, double d, double M) {
	double t_0 = (c0 * (d * d)) / ((w * h) * (D * D));
	return (c0 / (2.0 * w)) * (t_0 + sqrt(((t_0 * t_0) - (M * M))));
}
real(8) function code(c0, w, h, d, d_1, m)
    real(8), intent (in) :: c0
    real(8), intent (in) :: w
    real(8), intent (in) :: h
    real(8), intent (in) :: d
    real(8), intent (in) :: d_1
    real(8), intent (in) :: m
    real(8) :: t_0
    t_0 = (c0 * (d_1 * d_1)) / ((w * h) * (d * d))
    code = (c0 / (2.0d0 * w)) * (t_0 + sqrt(((t_0 * t_0) - (m * m))))
end function
public static double code(double c0, double w, double h, double D, double d, double M) {
	double t_0 = (c0 * (d * d)) / ((w * h) * (D * D));
	return (c0 / (2.0 * w)) * (t_0 + Math.sqrt(((t_0 * t_0) - (M * M))));
}
def code(c0, w, h, D, d, M):
	t_0 = (c0 * (d * d)) / ((w * h) * (D * D))
	return (c0 / (2.0 * w)) * (t_0 + math.sqrt(((t_0 * t_0) - (M * M))))
function code(c0, w, h, D, d, M)
	t_0 = Float64(Float64(c0 * Float64(d * d)) / Float64(Float64(w * h) * Float64(D * D)))
	return Float64(Float64(c0 / Float64(2.0 * w)) * Float64(t_0 + sqrt(Float64(Float64(t_0 * t_0) - Float64(M * M)))))
end
function tmp = code(c0, w, h, D, d, M)
	t_0 = (c0 * (d * d)) / ((w * h) * (D * D));
	tmp = (c0 / (2.0 * w)) * (t_0 + sqrt(((t_0 * t_0) - (M * M))));
end
code[c0_, w_, h_, D_, d_, M_] := Block[{t$95$0 = N[(N[(c0 * N[(d * d), $MachinePrecision]), $MachinePrecision] / N[(N[(w * h), $MachinePrecision] * N[(D * D), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(N[(c0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision] * N[(t$95$0 + N[Sqrt[N[(N[(t$95$0 * t$95$0), $MachinePrecision] - N[(M * M), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}\\
\frac{c0}{2 \cdot w} \cdot \left(t\_0 + \sqrt{t\_0 \cdot t\_0 - M \cdot M}\right)
\end{array}
\end{array}

Alternative 1: 46.2% accurate, 7.2× speedup?

\[\begin{array}{l} \\ \frac{c0}{2 \cdot w} \cdot \left(2 \cdot \left(\frac{d}{D} \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d}{D}\right)\right)\right) \end{array} \]
(FPCore (c0 w h D d M)
 :precision binary64
 (* (/ c0 (* 2.0 w)) (* 2.0 (* (/ d D) (* (/ c0 (* w h)) (/ d D))))))
double code(double c0, double w, double h, double D, double d, double M) {
	return (c0 / (2.0 * w)) * (2.0 * ((d / D) * ((c0 / (w * h)) * (d / D))));
}
real(8) function code(c0, w, h, d, d_1, m)
    real(8), intent (in) :: c0
    real(8), intent (in) :: w
    real(8), intent (in) :: h
    real(8), intent (in) :: d
    real(8), intent (in) :: d_1
    real(8), intent (in) :: m
    code = (c0 / (2.0d0 * w)) * (2.0d0 * ((d_1 / d) * ((c0 / (w * h)) * (d_1 / d))))
end function
public static double code(double c0, double w, double h, double D, double d, double M) {
	return (c0 / (2.0 * w)) * (2.0 * ((d / D) * ((c0 / (w * h)) * (d / D))));
}
def code(c0, w, h, D, d, M):
	return (c0 / (2.0 * w)) * (2.0 * ((d / D) * ((c0 / (w * h)) * (d / D))))
function code(c0, w, h, D, d, M)
	return Float64(Float64(c0 / Float64(2.0 * w)) * Float64(2.0 * Float64(Float64(d / D) * Float64(Float64(c0 / Float64(w * h)) * Float64(d / D)))))
end
function tmp = code(c0, w, h, D, d, M)
	tmp = (c0 / (2.0 * w)) * (2.0 * ((d / D) * ((c0 / (w * h)) * (d / D))));
end
code[c0_, w_, h_, D_, d_, M_] := N[(N[(c0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision] * N[(2.0 * N[(N[(d / D), $MachinePrecision] * N[(N[(c0 / N[(w * h), $MachinePrecision]), $MachinePrecision] * N[(d / D), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{c0}{2 \cdot w} \cdot \left(2 \cdot \left(\frac{d}{D} \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d}{D}\right)\right)\right)
\end{array}
Derivation
  1. Initial program 26.6%

    \[\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \]
  2. Simplified26.2%

    \[\leadsto \color{blue}{\frac{c0}{2 \cdot w} \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D} + \sqrt{\left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\right) \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\right) - M \cdot M}\right)} \]
  3. Add Preprocessing
  4. Applied egg-rr43.2%

    \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{\mathsf{fma}\left(\sqrt{\mathsf{fma}\left(\frac{c0}{w \cdot h}, {\left(\frac{d}{D}\right)}^{2}, M\right)}, \sqrt{\mathsf{fma}\left(\frac{c0}{w \cdot h}, {\left(\frac{d}{D}\right)}^{2}, -M\right)}, \frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2}\right)} \]
  5. Step-by-step derivation
    1. add-cube-cbrt43.1%

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

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \mathsf{fma}\left(\color{blue}{{\left(\sqrt[3]{\sqrt{\mathsf{fma}\left(\frac{c0}{w \cdot h}, {\left(\frac{d}{D}\right)}^{2}, M\right)}}\right)}^{3}}, \sqrt{\mathsf{fma}\left(\frac{c0}{w \cdot h}, {\left(\frac{d}{D}\right)}^{2}, -M\right)}, \frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2}\right) \]
    3. associate-/r*43.2%

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \mathsf{fma}\left({\left(\sqrt[3]{\sqrt{\mathsf{fma}\left(\color{blue}{\frac{\frac{c0}{w}}{h}}, {\left(\frac{d}{D}\right)}^{2}, M\right)}}\right)}^{3}, \sqrt{\mathsf{fma}\left(\frac{c0}{w \cdot h}, {\left(\frac{d}{D}\right)}^{2}, -M\right)}, \frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2}\right) \]
  6. Applied egg-rr43.2%

    \[\leadsto \frac{c0}{2 \cdot w} \cdot \mathsf{fma}\left(\color{blue}{{\left(\sqrt[3]{\sqrt{\mathsf{fma}\left(\frac{\frac{c0}{w}}{h}, {\left(\frac{d}{D}\right)}^{2}, M\right)}}\right)}^{3}}, \sqrt{\mathsf{fma}\left(\frac{c0}{w \cdot h}, {\left(\frac{d}{D}\right)}^{2}, -M\right)}, \frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2}\right) \]
  7. Taylor expanded in c0 around inf 35.8%

    \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{\left(2 \cdot \frac{c0 \cdot {d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)} \]
  8. Step-by-step derivation
    1. *-commutative35.8%

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(2 \cdot \frac{c0 \cdot {d}^{2}}{{D}^{2} \cdot \color{blue}{\left(w \cdot h\right)}}\right) \]
    2. *-commutative35.8%

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(2 \cdot \frac{c0 \cdot {d}^{2}}{\color{blue}{\left(w \cdot h\right) \cdot {D}^{2}}}\right) \]
    3. times-frac34.8%

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(2 \cdot \color{blue}{\left(\frac{c0}{w \cdot h} \cdot \frac{{d}^{2}}{{D}^{2}}\right)}\right) \]
    4. unpow234.8%

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(2 \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{\color{blue}{d \cdot d}}{{D}^{2}}\right)\right) \]
    5. unpow234.8%

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(2 \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{\color{blue}{D \cdot D}}\right)\right) \]
    6. frac-times47.5%

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(2 \cdot \left(\frac{c0}{w \cdot h} \cdot \color{blue}{\left(\frac{d}{D} \cdot \frac{d}{D}\right)}\right)\right) \]
    7. associate-*r*53.7%

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(2 \cdot \color{blue}{\left(\left(\frac{c0}{w \cdot h} \cdot \frac{d}{D}\right) \cdot \frac{d}{D}\right)}\right) \]
    8. *-commutative53.7%

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(2 \cdot \left(\left(\frac{c0}{\color{blue}{h \cdot w}} \cdot \frac{d}{D}\right) \cdot \frac{d}{D}\right)\right) \]
  9. Applied egg-rr53.7%

    \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(2 \cdot \color{blue}{\left(\left(\frac{c0}{h \cdot w} \cdot \frac{d}{D}\right) \cdot \frac{d}{D}\right)}\right) \]
  10. Final simplification53.7%

    \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(2 \cdot \left(\frac{d}{D} \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d}{D}\right)\right)\right) \]
  11. Add Preprocessing

Alternative 2: 35.9% accurate, 12.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;M \leq 5 \cdot 10^{+84}:\\ \;\;\;\;c0 \cdot \frac{0}{w}\\ \mathbf{else}:\\ \;\;\;\;\left(c0 \cdot M\right) \cdot \frac{0.5}{w}\\ \end{array} \end{array} \]
(FPCore (c0 w h D d M)
 :precision binary64
 (if (<= M 5e+84) (* c0 (/ 0.0 w)) (* (* c0 M) (/ 0.5 w))))
double code(double c0, double w, double h, double D, double d, double M) {
	double tmp;
	if (M <= 5e+84) {
		tmp = c0 * (0.0 / w);
	} else {
		tmp = (c0 * M) * (0.5 / w);
	}
	return tmp;
}
real(8) function code(c0, w, h, d, d_1, m)
    real(8), intent (in) :: c0
    real(8), intent (in) :: w
    real(8), intent (in) :: h
    real(8), intent (in) :: d
    real(8), intent (in) :: d_1
    real(8), intent (in) :: m
    real(8) :: tmp
    if (m <= 5d+84) then
        tmp = c0 * (0.0d0 / w)
    else
        tmp = (c0 * m) * (0.5d0 / w)
    end if
    code = tmp
end function
public static double code(double c0, double w, double h, double D, double d, double M) {
	double tmp;
	if (M <= 5e+84) {
		tmp = c0 * (0.0 / w);
	} else {
		tmp = (c0 * M) * (0.5 / w);
	}
	return tmp;
}
def code(c0, w, h, D, d, M):
	tmp = 0
	if M <= 5e+84:
		tmp = c0 * (0.0 / w)
	else:
		tmp = (c0 * M) * (0.5 / w)
	return tmp
function code(c0, w, h, D, d, M)
	tmp = 0.0
	if (M <= 5e+84)
		tmp = Float64(c0 * Float64(0.0 / w));
	else
		tmp = Float64(Float64(c0 * M) * Float64(0.5 / w));
	end
	return tmp
end
function tmp_2 = code(c0, w, h, D, d, M)
	tmp = 0.0;
	if (M <= 5e+84)
		tmp = c0 * (0.0 / w);
	else
		tmp = (c0 * M) * (0.5 / w);
	end
	tmp_2 = tmp;
end
code[c0_, w_, h_, D_, d_, M_] := If[LessEqual[M, 5e+84], N[(c0 * N[(0.0 / w), $MachinePrecision]), $MachinePrecision], N[(N[(c0 * M), $MachinePrecision] * N[(0.5 / w), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;M \leq 5 \cdot 10^{+84}:\\
\;\;\;\;c0 \cdot \frac{0}{w}\\

\mathbf{else}:\\
\;\;\;\;\left(c0 \cdot M\right) \cdot \frac{0.5}{w}\\


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

    1. Initial program 27.8%

      \[\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \]
    2. Simplified33.2%

      \[\leadsto \color{blue}{c0 \cdot \frac{\mathsf{fma}\left(c0, d \cdot \frac{d}{D \cdot \left(w \cdot \left(h \cdot D\right)\right)}, \sqrt{\mathsf{fma}\left(c0, d \cdot \frac{d}{D \cdot \left(w \cdot \left(h \cdot D\right)\right)}, M\right) \cdot \mathsf{fma}\left(\frac{c0}{w \cdot \left(h \cdot D\right)}, \frac{d \cdot d}{D}, -M\right)}\right)}{2 \cdot w}} \]
    3. Add Preprocessing
    4. Taylor expanded in c0 around -inf 3.0%

      \[\leadsto c0 \cdot \color{blue}{\left(-0.5 \cdot \frac{c0 \cdot \left(-1 \cdot \frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)} + \frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)}{w}\right)} \]
    5. Step-by-step derivation
      1. associate-*r/3.0%

        \[\leadsto c0 \cdot \color{blue}{\frac{-0.5 \cdot \left(c0 \cdot \left(-1 \cdot \frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)} + \frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)\right)}{w}} \]
      2. distribute-lft-in2.4%

        \[\leadsto c0 \cdot \frac{-0.5 \cdot \color{blue}{\left(c0 \cdot \left(-1 \cdot \frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right) + c0 \cdot \frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)}}{w} \]
      3. mul-1-neg2.4%

        \[\leadsto c0 \cdot \frac{-0.5 \cdot \left(c0 \cdot \color{blue}{\left(-\frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)} + c0 \cdot \frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)}{w} \]
      4. distribute-rgt-neg-in2.4%

        \[\leadsto c0 \cdot \frac{-0.5 \cdot \left(\color{blue}{\left(-c0 \cdot \frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)} + c0 \cdot \frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)}{w} \]
      5. associate-/l*3.4%

        \[\leadsto c0 \cdot \frac{-0.5 \cdot \left(\left(-\color{blue}{\frac{c0 \cdot {d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}}\right) + c0 \cdot \frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)}{w} \]
      6. mul-1-neg3.4%

        \[\leadsto c0 \cdot \frac{-0.5 \cdot \left(\color{blue}{-1 \cdot \frac{c0 \cdot {d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}} + c0 \cdot \frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)}{w} \]
      7. associate-/l*3.8%

        \[\leadsto c0 \cdot \frac{-0.5 \cdot \left(-1 \cdot \frac{c0 \cdot {d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)} + \color{blue}{\frac{c0 \cdot {d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}}\right)}{w} \]
      8. distribute-lft1-in3.8%

        \[\leadsto c0 \cdot \frac{-0.5 \cdot \color{blue}{\left(\left(-1 + 1\right) \cdot \frac{c0 \cdot {d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)}}{w} \]
      9. metadata-eval3.8%

        \[\leadsto c0 \cdot \frac{-0.5 \cdot \left(\color{blue}{0} \cdot \frac{c0 \cdot {d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)}{w} \]
      10. mul0-lft33.2%

        \[\leadsto c0 \cdot \frac{-0.5 \cdot \color{blue}{0}}{w} \]
      11. metadata-eval33.2%

        \[\leadsto c0 \cdot \frac{\color{blue}{0}}{w} \]
    6. Simplified33.2%

      \[\leadsto c0 \cdot \color{blue}{\frac{0}{w}} \]

    if 5.0000000000000001e84 < M

    1. Initial program 20.1%

      \[\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \]
    2. Simplified20.1%

      \[\leadsto \color{blue}{\frac{c0}{2 \cdot w} \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D} + \sqrt{\left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\right) \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\right) - M \cdot M}\right)} \]
    3. Add Preprocessing
    4. Applied egg-rr47.6%

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{\mathsf{fma}\left(\sqrt{\mathsf{fma}\left(\frac{c0}{w \cdot h}, {\left(\frac{d}{D}\right)}^{2}, M\right)}, \sqrt{\mathsf{fma}\left(\frac{c0}{w \cdot h}, {\left(\frac{d}{D}\right)}^{2}, -M\right)}, \frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2}\right)} \]
    5. Step-by-step derivation
      1. add-cube-cbrt47.6%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \mathsf{fma}\left(\color{blue}{\left(\sqrt[3]{\sqrt{\mathsf{fma}\left(\frac{c0}{w \cdot h}, {\left(\frac{d}{D}\right)}^{2}, M\right)}} \cdot \sqrt[3]{\sqrt{\mathsf{fma}\left(\frac{c0}{w \cdot h}, {\left(\frac{d}{D}\right)}^{2}, M\right)}}\right) \cdot \sqrt[3]{\sqrt{\mathsf{fma}\left(\frac{c0}{w \cdot h}, {\left(\frac{d}{D}\right)}^{2}, M\right)}}}, \sqrt{\mathsf{fma}\left(\frac{c0}{w \cdot h}, {\left(\frac{d}{D}\right)}^{2}, -M\right)}, \frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2}\right) \]
      2. pow347.6%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \mathsf{fma}\left(\color{blue}{{\left(\sqrt[3]{\sqrt{\mathsf{fma}\left(\frac{c0}{w \cdot h}, {\left(\frac{d}{D}\right)}^{2}, M\right)}}\right)}^{3}}, \sqrt{\mathsf{fma}\left(\frac{c0}{w \cdot h}, {\left(\frac{d}{D}\right)}^{2}, -M\right)}, \frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2}\right) \]
      3. associate-/r*47.6%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \mathsf{fma}\left({\left(\sqrt[3]{\sqrt{\mathsf{fma}\left(\color{blue}{\frac{\frac{c0}{w}}{h}}, {\left(\frac{d}{D}\right)}^{2}, M\right)}}\right)}^{3}, \sqrt{\mathsf{fma}\left(\frac{c0}{w \cdot h}, {\left(\frac{d}{D}\right)}^{2}, -M\right)}, \frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2}\right) \]
    6. Applied egg-rr47.6%

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \mathsf{fma}\left(\color{blue}{{\left(\sqrt[3]{\sqrt{\mathsf{fma}\left(\frac{\frac{c0}{w}}{h}, {\left(\frac{d}{D}\right)}^{2}, M\right)}}\right)}^{3}}, \sqrt{\mathsf{fma}\left(\frac{c0}{w \cdot h}, {\left(\frac{d}{D}\right)}^{2}, -M\right)}, \frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2}\right) \]
    7. Applied egg-rr31.0%

      \[\leadsto \color{blue}{{\left({\left(\frac{c0}{w} \cdot \frac{\mathsf{fma}\left({\left(\frac{d}{D}\right)}^{2}, \frac{c0}{w \cdot h}, M\right) + {\left(\frac{d}{D}\right)}^{2} \cdot \frac{c0}{w \cdot h}}{2}\right)}^{3}\right)}^{0.3333333333333333}} \]
    8. Taylor expanded in c0 around 0 36.3%

      \[\leadsto \color{blue}{0.5 \cdot \frac{M \cdot c0}{w}} \]
    9. Step-by-step derivation
      1. associate-*r/36.3%

        \[\leadsto \color{blue}{\frac{0.5 \cdot \left(M \cdot c0\right)}{w}} \]
      2. *-commutative36.3%

        \[\leadsto \frac{\color{blue}{\left(M \cdot c0\right) \cdot 0.5}}{w} \]
      3. associate-/l*36.3%

        \[\leadsto \color{blue}{\left(M \cdot c0\right) \cdot \frac{0.5}{w}} \]
    10. Simplified36.3%

      \[\leadsto \color{blue}{\left(M \cdot c0\right) \cdot \frac{0.5}{w}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification33.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;M \leq 5 \cdot 10^{+84}:\\ \;\;\;\;c0 \cdot \frac{0}{w}\\ \mathbf{else}:\\ \;\;\;\;\left(c0 \cdot M\right) \cdot \frac{0.5}{w}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 34.3% accurate, 30.2× speedup?

\[\begin{array}{l} \\ c0 \cdot \frac{0}{w} \end{array} \]
(FPCore (c0 w h D d M) :precision binary64 (* c0 (/ 0.0 w)))
double code(double c0, double w, double h, double D, double d, double M) {
	return c0 * (0.0 / w);
}
real(8) function code(c0, w, h, d, d_1, m)
    real(8), intent (in) :: c0
    real(8), intent (in) :: w
    real(8), intent (in) :: h
    real(8), intent (in) :: d
    real(8), intent (in) :: d_1
    real(8), intent (in) :: m
    code = c0 * (0.0d0 / w)
end function
public static double code(double c0, double w, double h, double D, double d, double M) {
	return c0 * (0.0 / w);
}
def code(c0, w, h, D, d, M):
	return c0 * (0.0 / w)
function code(c0, w, h, D, d, M)
	return Float64(c0 * Float64(0.0 / w))
end
function tmp = code(c0, w, h, D, d, M)
	tmp = c0 * (0.0 / w);
end
code[c0_, w_, h_, D_, d_, M_] := N[(c0 * N[(0.0 / w), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
c0 \cdot \frac{0}{w}
\end{array}
Derivation
  1. Initial program 26.6%

    \[\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \]
  2. Simplified35.1%

    \[\leadsto \color{blue}{c0 \cdot \frac{\mathsf{fma}\left(c0, d \cdot \frac{d}{D \cdot \left(w \cdot \left(h \cdot D\right)\right)}, \sqrt{\mathsf{fma}\left(c0, d \cdot \frac{d}{D \cdot \left(w \cdot \left(h \cdot D\right)\right)}, M\right) \cdot \mathsf{fma}\left(\frac{c0}{w \cdot \left(h \cdot D\right)}, \frac{d \cdot d}{D}, -M\right)}\right)}{2 \cdot w}} \]
  3. Add Preprocessing
  4. Taylor expanded in c0 around -inf 2.5%

    \[\leadsto c0 \cdot \color{blue}{\left(-0.5 \cdot \frac{c0 \cdot \left(-1 \cdot \frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)} + \frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)}{w}\right)} \]
  5. Step-by-step derivation
    1. associate-*r/2.5%

      \[\leadsto c0 \cdot \color{blue}{\frac{-0.5 \cdot \left(c0 \cdot \left(-1 \cdot \frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)} + \frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)\right)}{w}} \]
    2. distribute-lft-in2.1%

      \[\leadsto c0 \cdot \frac{-0.5 \cdot \color{blue}{\left(c0 \cdot \left(-1 \cdot \frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right) + c0 \cdot \frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)}}{w} \]
    3. mul-1-neg2.1%

      \[\leadsto c0 \cdot \frac{-0.5 \cdot \left(c0 \cdot \color{blue}{\left(-\frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)} + c0 \cdot \frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)}{w} \]
    4. distribute-rgt-neg-in2.1%

      \[\leadsto c0 \cdot \frac{-0.5 \cdot \left(\color{blue}{\left(-c0 \cdot \frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)} + c0 \cdot \frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)}{w} \]
    5. associate-/l*3.7%

      \[\leadsto c0 \cdot \frac{-0.5 \cdot \left(\left(-\color{blue}{\frac{c0 \cdot {d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}}\right) + c0 \cdot \frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)}{w} \]
    6. mul-1-neg3.7%

      \[\leadsto c0 \cdot \frac{-0.5 \cdot \left(\color{blue}{-1 \cdot \frac{c0 \cdot {d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}} + c0 \cdot \frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)}{w} \]
    7. associate-/l*3.2%

      \[\leadsto c0 \cdot \frac{-0.5 \cdot \left(-1 \cdot \frac{c0 \cdot {d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)} + \color{blue}{\frac{c0 \cdot {d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}}\right)}{w} \]
    8. distribute-lft1-in3.2%

      \[\leadsto c0 \cdot \frac{-0.5 \cdot \color{blue}{\left(\left(-1 + 1\right) \cdot \frac{c0 \cdot {d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)}}{w} \]
    9. metadata-eval3.2%

      \[\leadsto c0 \cdot \frac{-0.5 \cdot \left(\color{blue}{0} \cdot \frac{c0 \cdot {d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)}{w} \]
    10. mul0-lft29.7%

      \[\leadsto c0 \cdot \frac{-0.5 \cdot \color{blue}{0}}{w} \]
    11. metadata-eval29.7%

      \[\leadsto c0 \cdot \frac{\color{blue}{0}}{w} \]
  6. Simplified29.7%

    \[\leadsto c0 \cdot \color{blue}{\frac{0}{w}} \]
  7. Add Preprocessing

Reproduce

?
herbie shell --seed 2024111 
(FPCore (c0 w h D d M)
  :name "Henrywood and Agarwal, Equation (13)"
  :precision binary64
  (* (/ c0 (* 2.0 w)) (+ (/ (* c0 (* d d)) (* (* w h) (* D D))) (sqrt (- (* (/ (* c0 (* d d)) (* (* w h) (* D D))) (/ (* c0 (* d d)) (* (* w h) (* D D)))) (* M M))))))