Henrywood and Agarwal, Equation (13)

Percentage Accurate: 24.2% → 53.5%
Time: 34.3s
Alternatives: 3
Speedup: 21.6×

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.2% 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: 53.5% accurate, 0.5× 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)}\\ t_1 := \frac{c0}{2 \cdot w} \cdot \left(t\_0 + \sqrt{t\_0 \cdot t\_0 - M \cdot M}\right)\\ \mathbf{if}\;t\_1 \leq \infty:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;c0 \cdot \frac{0}{2 \cdot w}\\ \end{array} \end{array} \]
(FPCore (c0 w h D d M)
 :precision binary64
 (let* ((t_0 (/ (* c0 (* d d)) (* (* w h) (* D D))))
        (t_1 (* (/ c0 (* 2.0 w)) (+ t_0 (sqrt (- (* t_0 t_0) (* M M)))))))
   (if (<= t_1 INFINITY) t_1 (* c0 (/ 0.0 (* 2.0 w))))))
double code(double c0, double w, double h, double D, double d, double M) {
	double t_0 = (c0 * (d * d)) / ((w * h) * (D * D));
	double t_1 = (c0 / (2.0 * w)) * (t_0 + sqrt(((t_0 * t_0) - (M * M))));
	double tmp;
	if (t_1 <= ((double) INFINITY)) {
		tmp = t_1;
	} else {
		tmp = c0 * (0.0 / (2.0 * w));
	}
	return tmp;
}
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));
	double t_1 = (c0 / (2.0 * w)) * (t_0 + Math.sqrt(((t_0 * t_0) - (M * M))));
	double tmp;
	if (t_1 <= Double.POSITIVE_INFINITY) {
		tmp = t_1;
	} else {
		tmp = c0 * (0.0 / (2.0 * w));
	}
	return tmp;
}
def code(c0, w, h, D, d, M):
	t_0 = (c0 * (d * d)) / ((w * h) * (D * D))
	t_1 = (c0 / (2.0 * w)) * (t_0 + math.sqrt(((t_0 * t_0) - (M * M))))
	tmp = 0
	if t_1 <= math.inf:
		tmp = t_1
	else:
		tmp = c0 * (0.0 / (2.0 * w))
	return tmp
function code(c0, w, h, D, d, M)
	t_0 = Float64(Float64(c0 * Float64(d * d)) / Float64(Float64(w * h) * Float64(D * D)))
	t_1 = Float64(Float64(c0 / Float64(2.0 * w)) * Float64(t_0 + sqrt(Float64(Float64(t_0 * t_0) - Float64(M * M)))))
	tmp = 0.0
	if (t_1 <= Inf)
		tmp = t_1;
	else
		tmp = Float64(c0 * Float64(0.0 / Float64(2.0 * w)));
	end
	return tmp
end
function tmp_2 = code(c0, w, h, D, d, M)
	t_0 = (c0 * (d * d)) / ((w * h) * (D * D));
	t_1 = (c0 / (2.0 * w)) * (t_0 + sqrt(((t_0 * t_0) - (M * M))));
	tmp = 0.0;
	if (t_1 <= Inf)
		tmp = t_1;
	else
		tmp = c0 * (0.0 / (2.0 * w));
	end
	tmp_2 = tmp;
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]}, Block[{t$95$1 = 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]}, If[LessEqual[t$95$1, Infinity], t$95$1, N[(c0 * N[(0.0 / N[(2.0 * w), $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)}\\
t_1 := \frac{c0}{2 \cdot w} \cdot \left(t\_0 + \sqrt{t\_0 \cdot t\_0 - M \cdot M}\right)\\
\mathbf{if}\;t\_1 \leq \infty:\\
\;\;\;\;t\_1\\

\mathbf{else}:\\
\;\;\;\;c0 \cdot \frac{0}{2 \cdot w}\\


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

    1. Initial program 79.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. Add Preprocessing

    if +inf.0 < (*.f64 (/.f64 c0 (*.f64 #s(literal 2 binary64) w)) (+.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (sqrt.f64 (-.f64 (*.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D)))) (*.f64 M M)))))

    1. Initial program 0.0%

      \[\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}{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 \left(c0 \cdot \left(d \cdot \frac{d}{D \cdot \left(w \cdot \left(h \cdot D\right)\right)}\right) - M\right)}\right)}{2 \cdot w}} \]
    3. Add Preprocessing
    4. Taylor expanded in c0 around -inf 1.4%

      \[\leadsto c0 \cdot \frac{\color{blue}{-1 \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)}}{2 \cdot w} \]
    5. Step-by-step derivation
      1. distribute-lft-in0.8%

        \[\leadsto c0 \cdot \frac{-1 \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)}}{2 \cdot w} \]
      2. mul-1-neg0.8%

        \[\leadsto c0 \cdot \frac{-1 \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)}{2 \cdot w} \]
      3. distribute-rgt-neg-in0.8%

        \[\leadsto c0 \cdot \frac{-1 \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)}{2 \cdot w} \]
      4. associate-/l*0.1%

        \[\leadsto c0 \cdot \frac{-1 \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)}{2 \cdot w} \]
      5. mul-1-neg0.1%

        \[\leadsto c0 \cdot \frac{-1 \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)}{2 \cdot w} \]
      6. associate-/l*0.1%

        \[\leadsto c0 \cdot \frac{-1 \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)}{2 \cdot w} \]
      7. distribute-lft1-in0.1%

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

        \[\leadsto c0 \cdot \frac{-1 \cdot \left(\color{blue}{0} \cdot \frac{c0 \cdot {d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)}{2 \cdot w} \]
      9. mul0-lft38.6%

        \[\leadsto c0 \cdot \frac{-1 \cdot \color{blue}{0}}{2 \cdot w} \]
      10. metadata-eval38.6%

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

      \[\leadsto c0 \cdot \frac{\color{blue}{0}}{2 \cdot w} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 2: 42.1% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c0 \leq -1 \cdot 10^{-183} \lor \neg \left(c0 \leq 6.5 \cdot 10^{-34}\right):\\ \;\;\;\;c0 \cdot \frac{2 \cdot \left(c0 \cdot \left(d \cdot \frac{d}{\left(w \cdot h\right) \cdot {D}^{2}}\right)\right)}{2 \cdot w}\\ \mathbf{else}:\\ \;\;\;\;c0 \cdot \frac{0}{2 \cdot w}\\ \end{array} \end{array} \]
(FPCore (c0 w h D d M)
 :precision binary64
 (if (or (<= c0 -1e-183) (not (<= c0 6.5e-34)))
   (* c0 (/ (* 2.0 (* c0 (* d (/ d (* (* w h) (pow D 2.0)))))) (* 2.0 w)))
   (* c0 (/ 0.0 (* 2.0 w)))))
double code(double c0, double w, double h, double D, double d, double M) {
	double tmp;
	if ((c0 <= -1e-183) || !(c0 <= 6.5e-34)) {
		tmp = c0 * ((2.0 * (c0 * (d * (d / ((w * h) * pow(D, 2.0)))))) / (2.0 * w));
	} else {
		tmp = c0 * (0.0 / (2.0 * 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 ((c0 <= (-1d-183)) .or. (.not. (c0 <= 6.5d-34))) then
        tmp = c0 * ((2.0d0 * (c0 * (d_1 * (d_1 / ((w * h) * (d ** 2.0d0)))))) / (2.0d0 * w))
    else
        tmp = c0 * (0.0d0 / (2.0d0 * 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 ((c0 <= -1e-183) || !(c0 <= 6.5e-34)) {
		tmp = c0 * ((2.0 * (c0 * (d * (d / ((w * h) * Math.pow(D, 2.0)))))) / (2.0 * w));
	} else {
		tmp = c0 * (0.0 / (2.0 * w));
	}
	return tmp;
}
def code(c0, w, h, D, d, M):
	tmp = 0
	if (c0 <= -1e-183) or not (c0 <= 6.5e-34):
		tmp = c0 * ((2.0 * (c0 * (d * (d / ((w * h) * math.pow(D, 2.0)))))) / (2.0 * w))
	else:
		tmp = c0 * (0.0 / (2.0 * w))
	return tmp
function code(c0, w, h, D, d, M)
	tmp = 0.0
	if ((c0 <= -1e-183) || !(c0 <= 6.5e-34))
		tmp = Float64(c0 * Float64(Float64(2.0 * Float64(c0 * Float64(d * Float64(d / Float64(Float64(w * h) * (D ^ 2.0)))))) / Float64(2.0 * w)));
	else
		tmp = Float64(c0 * Float64(0.0 / Float64(2.0 * w)));
	end
	return tmp
end
function tmp_2 = code(c0, w, h, D, d, M)
	tmp = 0.0;
	if ((c0 <= -1e-183) || ~((c0 <= 6.5e-34)))
		tmp = c0 * ((2.0 * (c0 * (d * (d / ((w * h) * (D ^ 2.0)))))) / (2.0 * w));
	else
		tmp = c0 * (0.0 / (2.0 * w));
	end
	tmp_2 = tmp;
end
code[c0_, w_, h_, D_, d_, M_] := If[Or[LessEqual[c0, -1e-183], N[Not[LessEqual[c0, 6.5e-34]], $MachinePrecision]], N[(c0 * N[(N[(2.0 * N[(c0 * N[(d * N[(d / N[(N[(w * h), $MachinePrecision] * N[Power[D, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(2.0 * w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(c0 * N[(0.0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;c0 \leq -1 \cdot 10^{-183} \lor \neg \left(c0 \leq 6.5 \cdot 10^{-34}\right):\\
\;\;\;\;c0 \cdot \frac{2 \cdot \left(c0 \cdot \left(d \cdot \frac{d}{\left(w \cdot h\right) \cdot {D}^{2}}\right)\right)}{2 \cdot w}\\

\mathbf{else}:\\
\;\;\;\;c0 \cdot \frac{0}{2 \cdot w}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c0 < -1.00000000000000001e-183 or 6.49999999999999985e-34 < c0

    1. Initial program 28.9%

      \[\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. Simplified44.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 \left(c0 \cdot \left(d \cdot \frac{d}{D \cdot \left(w \cdot \left(h \cdot D\right)\right)}\right) - M\right)}\right)}{2 \cdot w}} \]
    3. Add Preprocessing
    4. Step-by-step derivation
      1. clear-num44.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.00000000000000001e-183 < c0 < 6.49999999999999985e-34

    1. Initial program 23.9%

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

      \[\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 \left(c0 \cdot \left(d \cdot \frac{d}{D \cdot \left(w \cdot \left(h \cdot D\right)\right)}\right) - M\right)}\right)}{2 \cdot w}} \]
    3. Add Preprocessing
    4. Taylor expanded in c0 around -inf 8.0%

      \[\leadsto c0 \cdot \frac{\color{blue}{-1 \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)}}{2 \cdot w} \]
    5. Step-by-step derivation
      1. distribute-lft-in8.0%

        \[\leadsto c0 \cdot \frac{-1 \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)}}{2 \cdot w} \]
      2. mul-1-neg8.0%

        \[\leadsto c0 \cdot \frac{-1 \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)}{2 \cdot w} \]
      3. distribute-rgt-neg-in8.0%

        \[\leadsto c0 \cdot \frac{-1 \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)}{2 \cdot w} \]
      4. associate-/l*8.0%

        \[\leadsto c0 \cdot \frac{-1 \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)}{2 \cdot w} \]
      5. mul-1-neg8.0%

        \[\leadsto c0 \cdot \frac{-1 \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)}{2 \cdot w} \]
      6. associate-/l*8.1%

        \[\leadsto c0 \cdot \frac{-1 \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)}{2 \cdot w} \]
      7. distribute-lft1-in8.1%

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

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

        \[\leadsto c0 \cdot \frac{-1 \cdot \color{blue}{0}}{2 \cdot w} \]
      10. metadata-eval48.1%

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

      \[\leadsto c0 \cdot \frac{\color{blue}{0}}{2 \cdot w} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification44.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;c0 \leq -1 \cdot 10^{-183} \lor \neg \left(c0 \leq 6.5 \cdot 10^{-34}\right):\\ \;\;\;\;c0 \cdot \frac{2 \cdot \left(c0 \cdot \left(d \cdot \frac{d}{\left(w \cdot h\right) \cdot {D}^{2}}\right)\right)}{2 \cdot w}\\ \mathbf{else}:\\ \;\;\;\;c0 \cdot \frac{0}{2 \cdot w}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 33.1% accurate, 21.6× speedup?

\[\begin{array}{l} \\ c0 \cdot \frac{0}{2 \cdot w} \end{array} \]
(FPCore (c0 w h D d M) :precision binary64 (* c0 (/ 0.0 (* 2.0 w))))
double code(double c0, double w, double h, double D, double d, double M) {
	return c0 * (0.0 / (2.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 / (2.0d0 * w))
end function
public static double code(double c0, double w, double h, double D, double d, double M) {
	return c0 * (0.0 / (2.0 * w));
}
def code(c0, w, h, D, d, M):
	return c0 * (0.0 / (2.0 * w))
function code(c0, w, h, D, d, M)
	return Float64(c0 * Float64(0.0 / Float64(2.0 * w)))
end
function tmp = code(c0, w, h, D, d, M)
	tmp = c0 * (0.0 / (2.0 * w));
end
code[c0_, w_, h_, D_, d_, M_] := N[(c0 * N[(0.0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
c0 \cdot \frac{0}{2 \cdot w}
\end{array}
Derivation
  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. Simplified39.3%

    \[\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 \left(c0 \cdot \left(d \cdot \frac{d}{D \cdot \left(w \cdot \left(h \cdot D\right)\right)}\right) - M\right)}\right)}{2 \cdot w}} \]
  3. Add Preprocessing
  4. Taylor expanded in c0 around -inf 4.9%

    \[\leadsto c0 \cdot \frac{\color{blue}{-1 \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)}}{2 \cdot w} \]
  5. Step-by-step derivation
    1. distribute-lft-in4.4%

      \[\leadsto c0 \cdot \frac{-1 \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)}}{2 \cdot w} \]
    2. mul-1-neg4.4%

      \[\leadsto c0 \cdot \frac{-1 \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)}{2 \cdot w} \]
    3. distribute-rgt-neg-in4.4%

      \[\leadsto c0 \cdot \frac{-1 \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)}{2 \cdot w} \]
    4. associate-/l*3.3%

      \[\leadsto c0 \cdot \frac{-1 \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)}{2 \cdot w} \]
    5. mul-1-neg3.3%

      \[\leadsto c0 \cdot \frac{-1 \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)}{2 \cdot w} \]
    6. associate-/l*4.4%

      \[\leadsto c0 \cdot \frac{-1 \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)}{2 \cdot w} \]
    7. distribute-lft1-in4.4%

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

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

      \[\leadsto c0 \cdot \frac{-1 \cdot \color{blue}{0}}{2 \cdot w} \]
    10. metadata-eval29.7%

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

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

Reproduce

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