Henrywood and Agarwal, Equation (13)

Percentage Accurate: 24.7% → 54.8%
Time: 28.2s
Alternatives: 7
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 7 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.7% 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.8% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := d \cdot \frac{d}{D \cdot \left(w \cdot \left(h \cdot D\right)\right)}\\ t_1 := \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}\\ \mathbf{if}\;\frac{c0}{2 \cdot w} \cdot \left(t\_1 + \sqrt{t\_1 \cdot t\_1 - M \cdot M}\right) \leq \infty:\\ \;\;\;\;c0 \cdot \frac{\mathsf{fma}\left(c0, t\_0, \sqrt{\mathsf{fma}\left(c0, t\_0, M\right) \cdot \left(c0 \cdot t\_0 - M\right)}\right)}{2 \cdot w}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \end{array} \]
(FPCore (c0 w h D d M)
 :precision binary64
 (let* ((t_0 (* d (/ d (* D (* w (* h D))))))
        (t_1 (/ (* c0 (* d d)) (* (* w h) (* D D)))))
   (if (<=
        (* (/ c0 (* 2.0 w)) (+ t_1 (sqrt (- (* t_1 t_1) (* M M)))))
        INFINITY)
     (*
      c0
      (/ (fma c0 t_0 (sqrt (* (fma c0 t_0 M) (- (* c0 t_0) M)))) (* 2.0 w)))
     0.0)))
double code(double c0, double w, double h, double D, double d, double M) {
	double t_0 = d * (d / (D * (w * (h * D))));
	double t_1 = (c0 * (d * d)) / ((w * h) * (D * D));
	double tmp;
	if (((c0 / (2.0 * w)) * (t_1 + sqrt(((t_1 * t_1) - (M * M))))) <= ((double) INFINITY)) {
		tmp = c0 * (fma(c0, t_0, sqrt((fma(c0, t_0, M) * ((c0 * t_0) - M)))) / (2.0 * w));
	} else {
		tmp = 0.0;
	}
	return tmp;
}
function code(c0, w, h, D, d, M)
	t_0 = Float64(d * Float64(d / Float64(D * Float64(w * Float64(h * D)))))
	t_1 = Float64(Float64(c0 * Float64(d * d)) / Float64(Float64(w * h) * Float64(D * D)))
	tmp = 0.0
	if (Float64(Float64(c0 / Float64(2.0 * w)) * Float64(t_1 + sqrt(Float64(Float64(t_1 * t_1) - Float64(M * M))))) <= Inf)
		tmp = Float64(c0 * Float64(fma(c0, t_0, sqrt(Float64(fma(c0, t_0, M) * Float64(Float64(c0 * t_0) - M)))) / Float64(2.0 * w)));
	else
		tmp = 0.0;
	end
	return tmp
end
code[c0_, w_, h_, D_, d_, M_] := Block[{t$95$0 = N[(d * N[(d / N[(D * N[(w * N[(h * D), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(c0 * N[(d * d), $MachinePrecision]), $MachinePrecision] / N[(N[(w * h), $MachinePrecision] * N[(D * D), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[(c0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision] * N[(t$95$1 + N[Sqrt[N[(N[(t$95$1 * t$95$1), $MachinePrecision] - N[(M * M), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], Infinity], N[(c0 * N[(N[(c0 * t$95$0 + N[Sqrt[N[(N[(c0 * t$95$0 + M), $MachinePrecision] * N[(N[(c0 * t$95$0), $MachinePrecision] - M), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.0]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := d \cdot \frac{d}{D \cdot \left(w \cdot \left(h \cdot D\right)\right)}\\
t_1 := \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}\\
\mathbf{if}\;\frac{c0}{2 \cdot w} \cdot \left(t\_1 + \sqrt{t\_1 \cdot t\_1 - M \cdot M}\right) \leq \infty:\\
\;\;\;\;c0 \cdot \frac{\mathsf{fma}\left(c0, t\_0, \sqrt{\mathsf{fma}\left(c0, t\_0, M\right) \cdot \left(c0 \cdot t\_0 - M\right)}\right)}{2 \cdot w}\\

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

      \[\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. Simplified76.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 \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

    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. Simplified0.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-rr25.9%

      \[\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{\frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2} - M}, \frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2}\right)} \]
    5. Step-by-step derivation
      1. associate-/r*26.0%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-0.5 \cdot \frac{{c0}^{2} \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}} \]
    10. Step-by-step derivation
      1. associate-*r/0.0%

        \[\leadsto \color{blue}{\frac{-0.5 \cdot \left({c0}^{2} \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}} \]
    11. Simplified39.9%

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

Alternative 2: 55.2% accurate, 0.4× 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)}\\ \mathbf{if}\;\frac{c0}{2 \cdot w} \cdot \left(t\_0 + \sqrt{t\_0 \cdot t\_0 - M \cdot M}\right) \leq \infty:\\ \;\;\;\;c0 \cdot \frac{\frac{2 \cdot \frac{{d}^{2} \cdot \frac{c0}{w}}{h}}{{D}^{2}}}{2 \cdot w}\\ \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)))))
   (if (<=
        (* (/ c0 (* 2.0 w)) (+ t_0 (sqrt (- (* t_0 t_0) (* M M)))))
        INFINITY)
     (*
      c0
      (/ (/ (* 2.0 (/ (* (pow d 2.0) (/ c0 w)) h)) (pow D 2.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 tmp;
	if (((c0 / (2.0 * w)) * (t_0 + sqrt(((t_0 * t_0) - (M * M))))) <= ((double) INFINITY)) {
		tmp = c0 * (((2.0 * ((pow(d, 2.0) * (c0 / w)) / h)) / pow(D, 2.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 tmp;
	if (((c0 / (2.0 * w)) * (t_0 + Math.sqrt(((t_0 * t_0) - (M * M))))) <= Double.POSITIVE_INFINITY) {
		tmp = c0 * (((2.0 * ((Math.pow(d, 2.0) * (c0 / w)) / h)) / Math.pow(D, 2.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))
	tmp = 0
	if ((c0 / (2.0 * w)) * (t_0 + math.sqrt(((t_0 * t_0) - (M * M))))) <= math.inf:
		tmp = c0 * (((2.0 * ((math.pow(d, 2.0) * (c0 / w)) / h)) / math.pow(D, 2.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)))
	tmp = 0.0
	if (Float64(Float64(c0 / Float64(2.0 * w)) * Float64(t_0 + sqrt(Float64(Float64(t_0 * t_0) - Float64(M * M))))) <= Inf)
		tmp = Float64(c0 * Float64(Float64(Float64(2.0 * Float64(Float64((d ^ 2.0) * Float64(c0 / w)) / h)) / (D ^ 2.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));
	tmp = 0.0;
	if (((c0 / (2.0 * w)) * (t_0 + sqrt(((t_0 * t_0) - (M * M))))) <= Inf)
		tmp = c0 * (((2.0 * (((d ^ 2.0) * (c0 / w)) / h)) / (D ^ 2.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]}, If[LessEqual[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], Infinity], N[(c0 * N[(N[(N[(2.0 * N[(N[(N[Power[d, 2.0], $MachinePrecision] * N[(c0 / w), $MachinePrecision]), $MachinePrecision] / h), $MachinePrecision]), $MachinePrecision] / N[Power[D, 2.0], $MachinePrecision]), $MachinePrecision] / N[(2.0 * w), $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)}\\
\mathbf{if}\;\frac{c0}{2 \cdot w} \cdot \left(t\_0 + \sqrt{t\_0 \cdot t\_0 - M \cdot M}\right) \leq \infty:\\
\;\;\;\;c0 \cdot \frac{\frac{2 \cdot \frac{{d}^{2} \cdot \frac{c0}{w}}{h}}{{D}^{2}}}{2 \cdot w}\\

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

      \[\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. Simplified71.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. Taylor expanded in D around 0 30.9%

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

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

          \[\leadsto c0 \cdot \frac{\frac{\color{blue}{0.5 \cdot \left({D}^{2} \cdot \frac{h \cdot \left(w \cdot \left(0 \cdot \left(M \cdot \left({d}^{2} \cdot \frac{\frac{c0}{w}}{h}\right)\right)\right)\right)}{{d}^{2} \cdot c0}\right) + 2 \cdot \left({d}^{2} \cdot \frac{\frac{c0}{w}}{h}\right)}}{{D}^{2}}}{2 \cdot w} \]
      3. Applied egg-rr72.2%

        \[\leadsto c0 \cdot \frac{\frac{\color{blue}{0.5 \cdot \frac{{D}^{2} \cdot 0}{c0 \cdot {d}^{2}} + 2 \cdot \frac{{d}^{2} \cdot \frac{c0}{w}}{h}}}{{D}^{2}}}{2 \cdot w} \]
      4. Taylor expanded in D around 0 74.3%

        \[\leadsto c0 \cdot \frac{\frac{\color{blue}{0} + 2 \cdot \frac{{d}^{2} \cdot \frac{c0}{w}}{h}}{{D}^{2}}}{2 \cdot w} \]

      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. Simplified0.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-rr25.9%

        \[\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{\frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2} - M}, \frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2}\right)} \]
      5. Step-by-step derivation
        1. associate-/r*26.0%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{-0.5 \cdot \frac{{c0}^{2} \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}} \]
      10. Step-by-step derivation
        1. associate-*r/0.0%

          \[\leadsto \color{blue}{\frac{-0.5 \cdot \left({c0}^{2} \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}} \]
      11. Simplified39.9%

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

      \[\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:\\ \;\;\;\;c0 \cdot \frac{\frac{2 \cdot \frac{{d}^{2} \cdot \frac{c0}{w}}{h}}{{D}^{2}}}{2 \cdot w}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    8. Add Preprocessing

    Alternative 3: 55.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 72.5%

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

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

          \[\leadsto \left(c0 \cdot \frac{1}{\color{blue}{w \cdot 2}}\right) \cdot \mathsf{fma}\left(\sqrt{\mathsf{fma}\left(\frac{\frac{c0}{w}}{h}, {\left(\frac{d}{D}\right)}^{2}, M\right)}, \sqrt{\frac{\frac{c0}{w}}{h} \cdot {\left(\frac{d}{D}\right)}^{2} - M}, \frac{\frac{c0}{w}}{h} \cdot {\left(\frac{d}{D}\right)}^{2}\right) \]
      4. Applied egg-rr72.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. Simplified0.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-rr25.9%

        \[\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{\frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2} - M}, \frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2}\right)} \]
      5. Step-by-step derivation
        1. associate-/r*26.0%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{-0.5 \cdot \frac{{c0}^{2} \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}} \]
      10. Step-by-step derivation
        1. associate-*r/0.0%

          \[\leadsto \color{blue}{\frac{-0.5 \cdot \left({c0}^{2} \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}} \]
      11. Simplified39.9%

        \[\leadsto \color{blue}{0} \]
    3. Recombined 2 regimes into one program.
    4. Final simplification52.9%

      \[\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} \]
    5. Add Preprocessing

    Alternative 4: 55.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 72.5%

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

        \[\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{\frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2} - M}, \frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2}\right)} \]
      5. Step-by-step derivation
        1. associate-/r*26.0%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{-0.5 \cdot \frac{{c0}^{2} \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}} \]
      10. Step-by-step derivation
        1. associate-*r/0.0%

          \[\leadsto \color{blue}{\frac{-0.5 \cdot \left({c0}^{2} \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}} \]
      11. Simplified39.9%

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

    Alternative 5: 34.4% accurate, 0.9× speedup?

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

      1. Initial program 24.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. Simplified22.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-rr41.5%

        \[\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{\frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2} - M}, \frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2}\right)} \]
      5. Step-by-step derivation
        1. associate-/r*41.0%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{-0.5 \cdot \frac{{c0}^{2} \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}} \]
      10. Step-by-step derivation
        1. associate-*r/1.8%

          \[\leadsto \color{blue}{\frac{-0.5 \cdot \left({c0}^{2} \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}} \]
      11. Simplified28.6%

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

      if 3.5e-106 < d < 3.9e124

      1. Initial program 43.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. Simplified45.0%

        \[\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. Taylor expanded in c0 around 0 45.0%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(\color{blue}{\frac{c0}{h \cdot w}} \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) \]
      5. Step-by-step derivation
        1. *-commutative45.0%

          \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(\frac{c0}{\color{blue}{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) \]
        2. associate-/r*45.1%

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

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(\color{blue}{\frac{\frac{c0}{w}}{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. Recombined 2 regimes into one program.
    4. Final simplification32.3%

      \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq 3.5 \cdot 10^{-106}:\\ \;\;\;\;0\\ \mathbf{elif}\;d \leq 3.9 \cdot 10^{+124}:\\ \;\;\;\;\frac{c0}{2 \cdot w} \cdot \left(\frac{\frac{c0}{w}}{h} \cdot \frac{d \cdot d}{D \cdot D} + \sqrt{\left(\frac{d \cdot d}{D \cdot D} \cdot \frac{c0}{w \cdot h}\right) \cdot \left(\frac{d \cdot d}{D \cdot D} \cdot \frac{c0}{w \cdot h}\right) - M \cdot M}\right)\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    5. Add Preprocessing

    Alternative 6: 34.2% accurate, 0.9× speedup?

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

      1. Initial program 24.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. Simplified22.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-rr41.5%

        \[\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{\frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2} - M}, \frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2}\right)} \]
      5. Step-by-step derivation
        1. associate-/r*41.0%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{-0.5 \cdot \frac{{c0}^{2} \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}} \]
      10. Step-by-step derivation
        1. associate-*r/1.8%

          \[\leadsto \color{blue}{\frac{-0.5 \cdot \left({c0}^{2} \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}} \]
      11. Simplified28.6%

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

      if 2.00000000000000008e-108 < d < 3.4e124

      1. Initial program 43.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. Simplified45.0%

        \[\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-frac45.0%

          \[\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-rr45.0%

        \[\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) \]
    3. Recombined 2 regimes into one program.
    4. Final simplification32.3%

      \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq 2 \cdot 10^{-108}:\\ \;\;\;\;0\\ \mathbf{elif}\;d \leq 3.4 \cdot 10^{+124}:\\ \;\;\;\;\frac{c0}{2 \cdot w} \cdot \left(\sqrt{\left(\frac{d \cdot d}{D \cdot D} \cdot \frac{c0}{w \cdot h}\right) \cdot \left(\frac{d \cdot d}{D \cdot D} \cdot \frac{c0}{w \cdot h}\right) - M \cdot M} + \frac{c0}{w \cdot h} \cdot \left(\frac{d}{D} \cdot \frac{d}{D}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    5. Add Preprocessing

    Alternative 7: 34.6% 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 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. Simplified27.4%

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

      \[\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{\frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2} - M}, \frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2}\right)} \]
    5. Step-by-step derivation
      1. associate-/r*44.4%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-0.5 \cdot \frac{{c0}^{2} \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}} \]
    10. Step-by-step derivation
      1. associate-*r/2.3%

        \[\leadsto \color{blue}{\frac{-0.5 \cdot \left({c0}^{2} \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}} \]
    11. Simplified28.0%

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

    Reproduce

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