Henrywood and Agarwal, Equation (13)

Percentage Accurate: 24.3% → 54.5%
Time: 27.6s
Alternatives: 4
Speedup: 151.0×

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 4 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.3% 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: 54.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 := t\_0 + \sqrt{t\_0 \cdot t\_0 - M \cdot M}\\ \mathbf{if}\;\frac{c0}{2 \cdot w} \cdot t\_1 \leq \infty:\\ \;\;\;\;t\_1 \cdot \left(c0 \cdot \frac{1}{2 \cdot w}\right)\\ \mathbf{else}:\\ \;\;\;\;0\\ \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 (+ t_0 (sqrt (- (* t_0 t_0) (* M M))))))
   (if (<= (* (/ c0 (* 2.0 w)) t_1) INFINITY)
     (* t_1 (* c0 (/ 1.0 (* 2.0 w))))
     0.0)))
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 = t_0 + sqrt(((t_0 * t_0) - (M * M)));
	double tmp;
	if (((c0 / (2.0 * w)) * t_1) <= ((double) INFINITY)) {
		tmp = t_1 * (c0 * (1.0 / (2.0 * w)));
	} else {
		tmp = 0.0;
	}
	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 = t_0 + Math.sqrt(((t_0 * t_0) - (M * M)));
	double tmp;
	if (((c0 / (2.0 * w)) * t_1) <= Double.POSITIVE_INFINITY) {
		tmp = t_1 * (c0 * (1.0 / (2.0 * w)));
	} else {
		tmp = 0.0;
	}
	return tmp;
}
def code(c0, w, h, D, d, M):
	t_0 = (c0 * (d * d)) / ((w * h) * (D * D))
	t_1 = t_0 + math.sqrt(((t_0 * t_0) - (M * M)))
	tmp = 0
	if ((c0 / (2.0 * w)) * t_1) <= math.inf:
		tmp = t_1 * (c0 * (1.0 / (2.0 * w)))
	else:
		tmp = 0.0
	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(t_0 + sqrt(Float64(Float64(t_0 * t_0) - Float64(M * M))))
	tmp = 0.0
	if (Float64(Float64(c0 / Float64(2.0 * w)) * t_1) <= Inf)
		tmp = Float64(t_1 * Float64(c0 * Float64(1.0 / Float64(2.0 * w))));
	else
		tmp = 0.0;
	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 = t_0 + sqrt(((t_0 * t_0) - (M * M)));
	tmp = 0.0;
	if (((c0 / (2.0 * w)) * t_1) <= Inf)
		tmp = t_1 * (c0 * (1.0 / (2.0 * w)));
	else
		tmp = 0.0;
	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[(t$95$0 + N[Sqrt[N[(N[(t$95$0 * t$95$0), $MachinePrecision] - N[(M * M), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[(c0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision] * t$95$1), $MachinePrecision], Infinity], N[(t$95$1 * N[(c0 * N[(1.0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.0]]]
\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 := t\_0 + \sqrt{t\_0 \cdot t\_0 - M \cdot M}\\
\mathbf{if}\;\frac{c0}{2 \cdot w} \cdot t\_1 \leq \infty:\\
\;\;\;\;t\_1 \cdot \left(c0 \cdot \frac{1}{2 \cdot w}\right)\\

\mathbf{else}:\\
\;\;\;\;0\\


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

      \[\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
    3. Step-by-step derivation
      1. div-inv74.5%

        \[\leadsto \color{blue}{\left(c0 \cdot \frac{1}{2 \cdot w}\right)} \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. *-commutative74.5%

        \[\leadsto \left(c0 \cdot \frac{1}{\color{blue}{w \cdot 2}}\right) \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) \]
    4. Applied egg-rr74.5%

      \[\leadsto \color{blue}{\left(c0 \cdot \frac{1}{w \cdot 2}\right)} \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) \]

    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. Simplified14.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. Applied egg-rr31.9%

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

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

        \[\leadsto \log \color{blue}{1} \]
      3. Step-by-step derivation
        1. metadata-eval39.9%

          \[\leadsto \color{blue}{0} \]
      4. Applied egg-rr39.9%

        \[\leadsto \color{blue}{0} \]
    6. Recombined 2 regimes into one program.
    7. Final simplification49.8%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\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) \leq \infty:\\ \;\;\;\;\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) \cdot \left(c0 \cdot \frac{1}{2 \cdot w}\right)\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    8. Add Preprocessing

    Alternative 2: 54.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}:\\ \;\;\;\;0\\ \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 0.0)))
    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 = 0.0;
    	}
    	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 = 0.0;
    	}
    	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 = 0.0
    	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 = 0.0;
    	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 = 0.0;
    	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, 0.0]]]
    
    \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}:\\
    \;\;\;\;0\\
    
    
    \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 74.4%

        \[\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. Simplified14.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. Applied egg-rr31.9%

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

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

          \[\leadsto \log \color{blue}{1} \]
        3. Step-by-step derivation
          1. metadata-eval39.9%

            \[\leadsto \color{blue}{0} \]
        4. Applied egg-rr39.9%

          \[\leadsto \color{blue}{0} \]
      6. Recombined 2 regimes into one program.
      7. Add Preprocessing

      Alternative 3: 33.6% accurate, 1.0× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{c0}{w \cdot h}\\ t_1 := t\_0 \cdot \frac{d \cdot d}{D \cdot D}\\ \mathbf{if}\;c0 \leq 3.4 \cdot 10^{+161}:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;\frac{c0}{2 \cdot w} \cdot \left(t\_0 \cdot \left(\frac{d}{D} \cdot \frac{d}{D}\right) + \sqrt{t\_1 \cdot t\_1 - M \cdot M}\right)\\ \end{array} \end{array} \]
      (FPCore (c0 w h D d M)
       :precision binary64
       (let* ((t_0 (/ c0 (* w h))) (t_1 (* t_0 (/ (* d d) (* D D)))))
         (if (<= c0 3.4e+161)
           0.0
           (*
            (/ c0 (* 2.0 w))
            (+ (* t_0 (* (/ d D) (/ d D))) (sqrt (- (* t_1 t_1) (* M M))))))))
      double code(double c0, double w, double h, double D, double d, double M) {
      	double t_0 = c0 / (w * h);
      	double t_1 = t_0 * ((d * d) / (D * D));
      	double tmp;
      	if (c0 <= 3.4e+161) {
      		tmp = 0.0;
      	} else {
      		tmp = (c0 / (2.0 * w)) * ((t_0 * ((d / D) * (d / D))) + sqrt(((t_1 * t_1) - (M * M))));
      	}
      	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) :: t_0
          real(8) :: t_1
          real(8) :: tmp
          t_0 = c0 / (w * h)
          t_1 = t_0 * ((d_1 * d_1) / (d * d))
          if (c0 <= 3.4d+161) then
              tmp = 0.0d0
          else
              tmp = (c0 / (2.0d0 * w)) * ((t_0 * ((d_1 / d) * (d_1 / d))) + sqrt(((t_1 * t_1) - (m * m))))
          end if
          code = tmp
      end function
      
      public static double code(double c0, double w, double h, double D, double d, double M) {
      	double t_0 = c0 / (w * h);
      	double t_1 = t_0 * ((d * d) / (D * D));
      	double tmp;
      	if (c0 <= 3.4e+161) {
      		tmp = 0.0;
      	} else {
      		tmp = (c0 / (2.0 * w)) * ((t_0 * ((d / D) * (d / D))) + Math.sqrt(((t_1 * t_1) - (M * M))));
      	}
      	return tmp;
      }
      
      def code(c0, w, h, D, d, M):
      	t_0 = c0 / (w * h)
      	t_1 = t_0 * ((d * d) / (D * D))
      	tmp = 0
      	if c0 <= 3.4e+161:
      		tmp = 0.0
      	else:
      		tmp = (c0 / (2.0 * w)) * ((t_0 * ((d / D) * (d / D))) + math.sqrt(((t_1 * t_1) - (M * M))))
      	return tmp
      
      function code(c0, w, h, D, d, M)
      	t_0 = Float64(c0 / Float64(w * h))
      	t_1 = Float64(t_0 * Float64(Float64(d * d) / Float64(D * D)))
      	tmp = 0.0
      	if (c0 <= 3.4e+161)
      		tmp = 0.0;
      	else
      		tmp = Float64(Float64(c0 / Float64(2.0 * w)) * Float64(Float64(t_0 * Float64(Float64(d / D) * Float64(d / D))) + sqrt(Float64(Float64(t_1 * t_1) - Float64(M * M)))));
      	end
      	return tmp
      end
      
      function tmp_2 = code(c0, w, h, D, d, M)
      	t_0 = c0 / (w * h);
      	t_1 = t_0 * ((d * d) / (D * D));
      	tmp = 0.0;
      	if (c0 <= 3.4e+161)
      		tmp = 0.0;
      	else
      		tmp = (c0 / (2.0 * w)) * ((t_0 * ((d / D) * (d / D))) + sqrt(((t_1 * t_1) - (M * M))));
      	end
      	tmp_2 = tmp;
      end
      
      code[c0_, w_, h_, D_, d_, M_] := Block[{t$95$0 = N[(c0 / N[(w * h), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 * N[(N[(d * d), $MachinePrecision] / N[(D * D), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c0, 3.4e+161], 0.0, N[(N[(c0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision] * N[(N[(t$95$0 * N[(N[(d / D), $MachinePrecision] * N[(d / D), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[Sqrt[N[(N[(t$95$1 * t$95$1), $MachinePrecision] - N[(M * M), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      t_0 := \frac{c0}{w \cdot h}\\
      t_1 := t\_0 \cdot \frac{d \cdot d}{D \cdot D}\\
      \mathbf{if}\;c0 \leq 3.4 \cdot 10^{+161}:\\
      \;\;\;\;0\\
      
      \mathbf{else}:\\
      \;\;\;\;\frac{c0}{2 \cdot w} \cdot \left(t\_0 \cdot \left(\frac{d}{D} \cdot \frac{d}{D}\right) + \sqrt{t\_1 \cdot t\_1 - M \cdot M}\right)\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if c0 < 3.39999999999999993e161

        1. Initial program 19.3%

          \[\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. Simplified24.9%

          \[\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. Applied egg-rr33.1%

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

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

            \[\leadsto \log \color{blue}{1} \]
          3. Step-by-step derivation
            1. metadata-eval34.7%

              \[\leadsto \color{blue}{0} \]
          4. Applied egg-rr34.7%

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

          if 3.39999999999999993e161 < c0

          1. Initial program 31.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. Simplified31.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. Step-by-step derivation
            1. times-frac31.1%

              \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(\frac{c0}{w \cdot h} \cdot \color{blue}{\left(\frac{d}{D} \cdot \frac{d}{D}\right)} + \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) \]
          5. Applied egg-rr31.1%

            \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(\frac{c0}{w \cdot h} \cdot \color{blue}{\left(\frac{d}{D} \cdot \frac{d}{D}\right)} + \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) \]
        6. Recombined 2 regimes into one program.
        7. Add Preprocessing

        Alternative 4: 33.8% accurate, 151.0× speedup?

        \[\begin{array}{l} \\ 0 \end{array} \]
        (FPCore (c0 w h D d M) :precision binary64 0.0)
        double code(double c0, double w, double h, double D, double d, double M) {
        	return 0.0;
        }
        
        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 = 0.0d0
        end function
        
        public static double code(double c0, double w, double h, double D, double d, double M) {
        	return 0.0;
        }
        
        def code(c0, w, h, D, d, M):
        	return 0.0
        
        function code(c0, w, h, D, d, M)
        	return 0.0
        end
        
        function tmp = code(c0, w, h, D, d, M)
        	tmp = 0.0;
        end
        
        code[c0_, w_, h_, D_, d_, M_] := 0.0
        
        \begin{array}{l}
        
        \\
        0
        \end{array}
        
        Derivation
        1. Initial program 21.2%

          \[\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. Simplified28.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 \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. Applied egg-rr35.9%

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

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

            \[\leadsto \log \color{blue}{1} \]
          3. Step-by-step derivation
            1. metadata-eval32.0%

              \[\leadsto \color{blue}{0} \]
          4. Applied egg-rr32.0%

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

          Reproduce

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