Henrywood and Agarwal, Equation (13)

Percentage Accurate: 25.1% → 54.7%
Time: 39.6s
Alternatives: 7
Speedup: 21.6×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 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: 25.1% 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.7% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := {\left(\frac{d}{D}\right)}^{2}\\ t_1 := \frac{c0 \cdot \left(d \cdot d\right)}{\left(D \cdot D\right) \cdot \left(w \cdot h\right)}\\ t_2 := \frac{c0}{2 \cdot w} \cdot \left(t\_1 + \sqrt{t\_1 \cdot t\_1 - M \cdot M}\right)\\ \mathbf{if}\;t\_2 \leq -1 \cdot 10^{-246}:\\ \;\;\;\;c0 \cdot \frac{\frac{1}{\frac{h}{2 \cdot \frac{c0 \cdot t\_0}{w}}}}{2 \cdot w}\\ \mathbf{elif}\;t\_2 \leq 0:\\ \;\;\;\;c0 \cdot \frac{\frac{{M}^{2}}{c0 \cdot \frac{t\_0}{w \cdot h} + \frac{\frac{c0}{h} \cdot \frac{{d}^{2}}{w}}{{D}^{2}}}}{2 \cdot w}\\ \mathbf{elif}\;t\_2 \leq \infty:\\ \;\;\;\;c0 \cdot \frac{2 \cdot \frac{c0 \cdot {d}^{2}}{\left(w \cdot h\right) \cdot {D}^{2}}}{2 \cdot w}\\ \mathbf{else}:\\ \;\;\;\;c0 \cdot \frac{0}{2 \cdot w}\\ \end{array} \end{array} \]
(FPCore (c0 w h D d M)
 :precision binary64
 (let* ((t_0 (pow (/ d D) 2.0))
        (t_1 (/ (* c0 (* d d)) (* (* D D) (* w h))))
        (t_2 (* (/ c0 (* 2.0 w)) (+ t_1 (sqrt (- (* t_1 t_1) (* M M)))))))
   (if (<= t_2 -1e-246)
     (* c0 (/ (/ 1.0 (/ h (* 2.0 (/ (* c0 t_0) w)))) (* 2.0 w)))
     (if (<= t_2 0.0)
       (*
        c0
        (/
         (/
          (pow M 2.0)
          (+
           (* c0 (/ t_0 (* w h)))
           (/ (* (/ c0 h) (/ (pow d 2.0) w)) (pow D 2.0))))
         (* 2.0 w)))
       (if (<= t_2 INFINITY)
         (*
          c0
          (/ (* 2.0 (/ (* c0 (pow d 2.0)) (* (* w h) (pow D 2.0)))) (* 2.0 w)))
         (* c0 (/ 0.0 (* 2.0 w))))))))
double code(double c0, double w, double h, double D, double d, double M) {
	double t_0 = pow((d / D), 2.0);
	double t_1 = (c0 * (d * d)) / ((D * D) * (w * h));
	double t_2 = (c0 / (2.0 * w)) * (t_1 + sqrt(((t_1 * t_1) - (M * M))));
	double tmp;
	if (t_2 <= -1e-246) {
		tmp = c0 * ((1.0 / (h / (2.0 * ((c0 * t_0) / w)))) / (2.0 * w));
	} else if (t_2 <= 0.0) {
		tmp = c0 * ((pow(M, 2.0) / ((c0 * (t_0 / (w * h))) + (((c0 / h) * (pow(d, 2.0) / w)) / pow(D, 2.0)))) / (2.0 * w));
	} else if (t_2 <= ((double) INFINITY)) {
		tmp = c0 * ((2.0 * ((c0 * pow(d, 2.0)) / ((w * h) * pow(D, 2.0)))) / (2.0 * w));
	} else {
		tmp = c0 * (0.0 / (2.0 * w));
	}
	return tmp;
}
public static double code(double c0, double w, double h, double D, double d, double M) {
	double t_0 = Math.pow((d / D), 2.0);
	double t_1 = (c0 * (d * d)) / ((D * D) * (w * h));
	double t_2 = (c0 / (2.0 * w)) * (t_1 + Math.sqrt(((t_1 * t_1) - (M * M))));
	double tmp;
	if (t_2 <= -1e-246) {
		tmp = c0 * ((1.0 / (h / (2.0 * ((c0 * t_0) / w)))) / (2.0 * w));
	} else if (t_2 <= 0.0) {
		tmp = c0 * ((Math.pow(M, 2.0) / ((c0 * (t_0 / (w * h))) + (((c0 / h) * (Math.pow(d, 2.0) / w)) / Math.pow(D, 2.0)))) / (2.0 * w));
	} else if (t_2 <= Double.POSITIVE_INFINITY) {
		tmp = c0 * ((2.0 * ((c0 * Math.pow(d, 2.0)) / ((w * h) * Math.pow(D, 2.0)))) / (2.0 * w));
	} else {
		tmp = c0 * (0.0 / (2.0 * w));
	}
	return tmp;
}
def code(c0, w, h, D, d, M):
	t_0 = math.pow((d / D), 2.0)
	t_1 = (c0 * (d * d)) / ((D * D) * (w * h))
	t_2 = (c0 / (2.0 * w)) * (t_1 + math.sqrt(((t_1 * t_1) - (M * M))))
	tmp = 0
	if t_2 <= -1e-246:
		tmp = c0 * ((1.0 / (h / (2.0 * ((c0 * t_0) / w)))) / (2.0 * w))
	elif t_2 <= 0.0:
		tmp = c0 * ((math.pow(M, 2.0) / ((c0 * (t_0 / (w * h))) + (((c0 / h) * (math.pow(d, 2.0) / w)) / math.pow(D, 2.0)))) / (2.0 * w))
	elif t_2 <= math.inf:
		tmp = c0 * ((2.0 * ((c0 * math.pow(d, 2.0)) / ((w * h) * math.pow(D, 2.0)))) / (2.0 * w))
	else:
		tmp = c0 * (0.0 / (2.0 * w))
	return tmp
function code(c0, w, h, D, d, M)
	t_0 = Float64(d / D) ^ 2.0
	t_1 = Float64(Float64(c0 * Float64(d * d)) / Float64(Float64(D * D) * Float64(w * h)))
	t_2 = Float64(Float64(c0 / Float64(2.0 * w)) * Float64(t_1 + sqrt(Float64(Float64(t_1 * t_1) - Float64(M * M)))))
	tmp = 0.0
	if (t_2 <= -1e-246)
		tmp = Float64(c0 * Float64(Float64(1.0 / Float64(h / Float64(2.0 * Float64(Float64(c0 * t_0) / w)))) / Float64(2.0 * w)));
	elseif (t_2 <= 0.0)
		tmp = Float64(c0 * Float64(Float64((M ^ 2.0) / Float64(Float64(c0 * Float64(t_0 / Float64(w * h))) + Float64(Float64(Float64(c0 / h) * Float64((d ^ 2.0) / w)) / (D ^ 2.0)))) / Float64(2.0 * w)));
	elseif (t_2 <= Inf)
		tmp = Float64(c0 * Float64(Float64(2.0 * Float64(Float64(c0 * (d ^ 2.0)) / Float64(Float64(w * h) * (D ^ 2.0)))) / Float64(2.0 * w)));
	else
		tmp = Float64(c0 * Float64(0.0 / Float64(2.0 * w)));
	end
	return tmp
end
function tmp_2 = code(c0, w, h, D, d, M)
	t_0 = (d / D) ^ 2.0;
	t_1 = (c0 * (d * d)) / ((D * D) * (w * h));
	t_2 = (c0 / (2.0 * w)) * (t_1 + sqrt(((t_1 * t_1) - (M * M))));
	tmp = 0.0;
	if (t_2 <= -1e-246)
		tmp = c0 * ((1.0 / (h / (2.0 * ((c0 * t_0) / w)))) / (2.0 * w));
	elseif (t_2 <= 0.0)
		tmp = c0 * (((M ^ 2.0) / ((c0 * (t_0 / (w * h))) + (((c0 / h) * ((d ^ 2.0) / w)) / (D ^ 2.0)))) / (2.0 * w));
	elseif (t_2 <= Inf)
		tmp = c0 * ((2.0 * ((c0 * (d ^ 2.0)) / ((w * h) * (D ^ 2.0)))) / (2.0 * w));
	else
		tmp = c0 * (0.0 / (2.0 * w));
	end
	tmp_2 = tmp;
end
code[c0_, w_, h_, D_, d_, M_] := Block[{t$95$0 = N[Power[N[(d / D), $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$1 = N[(N[(c0 * N[(d * d), $MachinePrecision]), $MachinePrecision] / N[(N[(D * D), $MachinePrecision] * N[(w * h), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = 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]}, If[LessEqual[t$95$2, -1e-246], N[(c0 * N[(N[(1.0 / N[(h / N[(2.0 * N[(N[(c0 * t$95$0), $MachinePrecision] / w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(2.0 * w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 0.0], N[(c0 * N[(N[(N[Power[M, 2.0], $MachinePrecision] / N[(N[(c0 * N[(t$95$0 / N[(w * h), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(c0 / h), $MachinePrecision] * N[(N[Power[d, 2.0], $MachinePrecision] / w), $MachinePrecision]), $MachinePrecision] / N[Power[D, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(2.0 * w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, Infinity], N[(c0 * N[(N[(2.0 * N[(N[(c0 * N[Power[d, 2.0], $MachinePrecision]), $MachinePrecision] / N[(N[(w * h), $MachinePrecision] * N[Power[D, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(2.0 * w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(c0 * N[(0.0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := {\left(\frac{d}{D}\right)}^{2}\\
t_1 := \frac{c0 \cdot \left(d \cdot d\right)}{\left(D \cdot D\right) \cdot \left(w \cdot h\right)}\\
t_2 := \frac{c0}{2 \cdot w} \cdot \left(t\_1 + \sqrt{t\_1 \cdot t\_1 - M \cdot M}\right)\\
\mathbf{if}\;t\_2 \leq -1 \cdot 10^{-246}:\\
\;\;\;\;c0 \cdot \frac{\frac{1}{\frac{h}{2 \cdot \frac{c0 \cdot t\_0}{w}}}}{2 \cdot w}\\

\mathbf{elif}\;t\_2 \leq 0:\\
\;\;\;\;c0 \cdot \frac{\frac{{M}^{2}}{c0 \cdot \frac{t\_0}{w \cdot h} + \frac{\frac{c0}{h} \cdot \frac{{d}^{2}}{w}}{{D}^{2}}}}{2 \cdot w}\\

\mathbf{elif}\;t\_2 \leq \infty:\\
\;\;\;\;c0 \cdot \frac{2 \cdot \frac{c0 \cdot {d}^{2}}{\left(w \cdot h\right) \cdot {D}^{2}}}{2 \cdot w}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 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))))) < -9.99999999999999956e-247

    1. Initial program 87.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. Simplified80.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 \left(c0 \cdot \left(d \cdot \frac{d}{D \cdot \left(w \cdot \left(h \cdot D\right)\right)}\right) - M\right)}\right)}{2 \cdot w}} \]
    3. Add Preprocessing
    4. Taylor expanded in h around 0 16.6%

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

        \[\leadsto c0 \cdot \frac{\color{blue}{\frac{\mathsf{fma}\left(0.5, {D}^{2} \cdot \left(h \cdot \frac{w \cdot 0}{c0 \cdot {d}^{2}}\right), 2 \cdot \frac{\frac{c0 \cdot {d}^{2}}{{D}^{2}}}{w}\right)}{h}}}{2 \cdot w} \]
      2. Taylor expanded in w around 0 87.5%

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

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

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

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

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

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

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

      if -9.99999999999999956e-247 < (*.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))))) < -0.0

      1. Initial program 33.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. Simplified12.7%

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

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

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

          \[\leadsto c0 \cdot \frac{\frac{\color{blue}{0} + {M}^{2}}{\frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2} - \sqrt{{\left(\frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2}\right)}^{2} - {M}^{2}}}}{2 \cdot w} \]
        3. associate-*l/57.8%

          \[\leadsto c0 \cdot \frac{\frac{0 + {M}^{2}}{\color{blue}{\frac{c0 \cdot {\left(\frac{d}{D}\right)}^{2}}{w \cdot h}} - \sqrt{{\left(\frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2}\right)}^{2} - {M}^{2}}}}{2 \cdot w} \]
        4. associate-/l*58.2%

          \[\leadsto c0 \cdot \frac{\frac{0 + {M}^{2}}{\color{blue}{c0 \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{w \cdot h}} - \sqrt{{\left(\frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2}\right)}^{2} - {M}^{2}}}}{2 \cdot w} \]
        5. *-commutative58.2%

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

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

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

        \[\leadsto c0 \cdot \frac{\frac{0 + {M}^{2}}{c0 \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h \cdot w} - \color{blue}{-1 \cdot \frac{c0 \cdot {d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}}}}{2 \cdot w} \]
      8. Step-by-step derivation
        1. mul-1-neg58.6%

          \[\leadsto c0 \cdot \frac{\frac{0 + {M}^{2}}{c0 \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h \cdot w} - \color{blue}{\left(-\frac{c0 \cdot {d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)}}}{2 \cdot w} \]
        2. times-frac58.6%

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

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

          \[\leadsto c0 \cdot \frac{\frac{0 + {M}^{2}}{c0 \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h \cdot w} - \left(-\color{blue}{\frac{c0 \cdot \frac{{d}^{2}}{h \cdot w}}{{D}^{2}}}\right)}}{2 \cdot w} \]
        2. *-commutative58.6%

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

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

          \[\leadsto c0 \cdot \frac{\frac{0 + {M}^{2}}{c0 \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h \cdot w} - \left(-\frac{\color{blue}{\frac{c0 \cdot {d}^{2}}{w \cdot h}}}{{D}^{2}}\right)}}{2 \cdot w} \]
        2. *-commutative58.6%

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

          \[\leadsto c0 \cdot \frac{\frac{0 + {M}^{2}}{c0 \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{h \cdot w} - \left(-\frac{\color{blue}{\frac{c0}{h} \cdot \frac{{d}^{2}}{w}}}{{D}^{2}}\right)}}{2 \cdot w} \]
      13. Simplified68.2%

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

      if -0.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))))) < +inf.0

      1. Initial program 73.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. Simplified73.5%

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

        \[\leadsto c0 \cdot \frac{\color{blue}{2 \cdot \frac{c0 \cdot {d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}}}{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. Simplified18.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    Alternative 2: 54.8% accurate, 0.2× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{c0 \cdot {d}^{2}}{\left(w \cdot h\right) \cdot {D}^{2}}\\ t_1 := {\left(\frac{d}{D}\right)}^{2}\\ t_2 := \frac{c0 \cdot \left(d \cdot d\right)}{\left(D \cdot D\right) \cdot \left(w \cdot h\right)}\\ t_3 := \frac{c0}{2 \cdot w} \cdot \left(t\_2 + \sqrt{t\_2 \cdot t\_2 - M \cdot M}\right)\\ \mathbf{if}\;t\_3 \leq -1 \cdot 10^{-246}:\\ \;\;\;\;c0 \cdot \frac{\frac{1}{\frac{h}{2 \cdot \frac{c0 \cdot t\_1}{w}}}}{2 \cdot w}\\ \mathbf{elif}\;t\_3 \leq 0:\\ \;\;\;\;c0 \cdot \frac{\frac{{M}^{2}}{t\_0 + t\_1 \cdot \frac{c0}{w \cdot h}}}{2 \cdot w}\\ \mathbf{elif}\;t\_3 \leq \infty:\\ \;\;\;\;c0 \cdot \frac{2 \cdot t\_0}{2 \cdot w}\\ \mathbf{else}:\\ \;\;\;\;c0 \cdot \frac{0}{2 \cdot w}\\ \end{array} \end{array} \]
    (FPCore (c0 w h D d M)
     :precision binary64
     (let* ((t_0 (/ (* c0 (pow d 2.0)) (* (* w h) (pow D 2.0))))
            (t_1 (pow (/ d D) 2.0))
            (t_2 (/ (* c0 (* d d)) (* (* D D) (* w h))))
            (t_3 (* (/ c0 (* 2.0 w)) (+ t_2 (sqrt (- (* t_2 t_2) (* M M)))))))
       (if (<= t_3 -1e-246)
         (* c0 (/ (/ 1.0 (/ h (* 2.0 (/ (* c0 t_1) w)))) (* 2.0 w)))
         (if (<= t_3 0.0)
           (* c0 (/ (/ (pow M 2.0) (+ t_0 (* t_1 (/ c0 (* w h))))) (* 2.0 w)))
           (if (<= t_3 INFINITY)
             (* c0 (/ (* 2.0 t_0) (* 2.0 w)))
             (* c0 (/ 0.0 (* 2.0 w))))))))
    double code(double c0, double w, double h, double D, double d, double M) {
    	double t_0 = (c0 * pow(d, 2.0)) / ((w * h) * pow(D, 2.0));
    	double t_1 = pow((d / D), 2.0);
    	double t_2 = (c0 * (d * d)) / ((D * D) * (w * h));
    	double t_3 = (c0 / (2.0 * w)) * (t_2 + sqrt(((t_2 * t_2) - (M * M))));
    	double tmp;
    	if (t_3 <= -1e-246) {
    		tmp = c0 * ((1.0 / (h / (2.0 * ((c0 * t_1) / w)))) / (2.0 * w));
    	} else if (t_3 <= 0.0) {
    		tmp = c0 * ((pow(M, 2.0) / (t_0 + (t_1 * (c0 / (w * h))))) / (2.0 * w));
    	} else if (t_3 <= ((double) INFINITY)) {
    		tmp = c0 * ((2.0 * t_0) / (2.0 * w));
    	} else {
    		tmp = c0 * (0.0 / (2.0 * w));
    	}
    	return tmp;
    }
    
    public static double code(double c0, double w, double h, double D, double d, double M) {
    	double t_0 = (c0 * Math.pow(d, 2.0)) / ((w * h) * Math.pow(D, 2.0));
    	double t_1 = Math.pow((d / D), 2.0);
    	double t_2 = (c0 * (d * d)) / ((D * D) * (w * h));
    	double t_3 = (c0 / (2.0 * w)) * (t_2 + Math.sqrt(((t_2 * t_2) - (M * M))));
    	double tmp;
    	if (t_3 <= -1e-246) {
    		tmp = c0 * ((1.0 / (h / (2.0 * ((c0 * t_1) / w)))) / (2.0 * w));
    	} else if (t_3 <= 0.0) {
    		tmp = c0 * ((Math.pow(M, 2.0) / (t_0 + (t_1 * (c0 / (w * h))))) / (2.0 * w));
    	} else if (t_3 <= Double.POSITIVE_INFINITY) {
    		tmp = c0 * ((2.0 * t_0) / (2.0 * w));
    	} else {
    		tmp = c0 * (0.0 / (2.0 * w));
    	}
    	return tmp;
    }
    
    def code(c0, w, h, D, d, M):
    	t_0 = (c0 * math.pow(d, 2.0)) / ((w * h) * math.pow(D, 2.0))
    	t_1 = math.pow((d / D), 2.0)
    	t_2 = (c0 * (d * d)) / ((D * D) * (w * h))
    	t_3 = (c0 / (2.0 * w)) * (t_2 + math.sqrt(((t_2 * t_2) - (M * M))))
    	tmp = 0
    	if t_3 <= -1e-246:
    		tmp = c0 * ((1.0 / (h / (2.0 * ((c0 * t_1) / w)))) / (2.0 * w))
    	elif t_3 <= 0.0:
    		tmp = c0 * ((math.pow(M, 2.0) / (t_0 + (t_1 * (c0 / (w * h))))) / (2.0 * w))
    	elif t_3 <= math.inf:
    		tmp = c0 * ((2.0 * t_0) / (2.0 * w))
    	else:
    		tmp = c0 * (0.0 / (2.0 * w))
    	return tmp
    
    function code(c0, w, h, D, d, M)
    	t_0 = Float64(Float64(c0 * (d ^ 2.0)) / Float64(Float64(w * h) * (D ^ 2.0)))
    	t_1 = Float64(d / D) ^ 2.0
    	t_2 = Float64(Float64(c0 * Float64(d * d)) / Float64(Float64(D * D) * Float64(w * h)))
    	t_3 = Float64(Float64(c0 / Float64(2.0 * w)) * Float64(t_2 + sqrt(Float64(Float64(t_2 * t_2) - Float64(M * M)))))
    	tmp = 0.0
    	if (t_3 <= -1e-246)
    		tmp = Float64(c0 * Float64(Float64(1.0 / Float64(h / Float64(2.0 * Float64(Float64(c0 * t_1) / w)))) / Float64(2.0 * w)));
    	elseif (t_3 <= 0.0)
    		tmp = Float64(c0 * Float64(Float64((M ^ 2.0) / Float64(t_0 + Float64(t_1 * Float64(c0 / Float64(w * h))))) / Float64(2.0 * w)));
    	elseif (t_3 <= Inf)
    		tmp = Float64(c0 * Float64(Float64(2.0 * t_0) / Float64(2.0 * w)));
    	else
    		tmp = Float64(c0 * Float64(0.0 / Float64(2.0 * w)));
    	end
    	return tmp
    end
    
    function tmp_2 = code(c0, w, h, D, d, M)
    	t_0 = (c0 * (d ^ 2.0)) / ((w * h) * (D ^ 2.0));
    	t_1 = (d / D) ^ 2.0;
    	t_2 = (c0 * (d * d)) / ((D * D) * (w * h));
    	t_3 = (c0 / (2.0 * w)) * (t_2 + sqrt(((t_2 * t_2) - (M * M))));
    	tmp = 0.0;
    	if (t_3 <= -1e-246)
    		tmp = c0 * ((1.0 / (h / (2.0 * ((c0 * t_1) / w)))) / (2.0 * w));
    	elseif (t_3 <= 0.0)
    		tmp = c0 * (((M ^ 2.0) / (t_0 + (t_1 * (c0 / (w * h))))) / (2.0 * w));
    	elseif (t_3 <= Inf)
    		tmp = c0 * ((2.0 * t_0) / (2.0 * w));
    	else
    		tmp = c0 * (0.0 / (2.0 * w));
    	end
    	tmp_2 = tmp;
    end
    
    code[c0_, w_, h_, D_, d_, M_] := Block[{t$95$0 = N[(N[(c0 * N[Power[d, 2.0], $MachinePrecision]), $MachinePrecision] / N[(N[(w * h), $MachinePrecision] * N[Power[D, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Power[N[(d / D), $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$2 = N[(N[(c0 * N[(d * d), $MachinePrecision]), $MachinePrecision] / N[(N[(D * D), $MachinePrecision] * N[(w * h), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(N[(c0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision] * N[(t$95$2 + N[Sqrt[N[(N[(t$95$2 * t$95$2), $MachinePrecision] - N[(M * M), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$3, -1e-246], N[(c0 * N[(N[(1.0 / N[(h / N[(2.0 * N[(N[(c0 * t$95$1), $MachinePrecision] / w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(2.0 * w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, 0.0], N[(c0 * N[(N[(N[Power[M, 2.0], $MachinePrecision] / N[(t$95$0 + N[(t$95$1 * N[(c0 / N[(w * h), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(2.0 * w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, Infinity], N[(c0 * N[(N[(2.0 * t$95$0), $MachinePrecision] / N[(2.0 * w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(c0 * N[(0.0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    t_0 := \frac{c0 \cdot {d}^{2}}{\left(w \cdot h\right) \cdot {D}^{2}}\\
    t_1 := {\left(\frac{d}{D}\right)}^{2}\\
    t_2 := \frac{c0 \cdot \left(d \cdot d\right)}{\left(D \cdot D\right) \cdot \left(w \cdot h\right)}\\
    t_3 := \frac{c0}{2 \cdot w} \cdot \left(t\_2 + \sqrt{t\_2 \cdot t\_2 - M \cdot M}\right)\\
    \mathbf{if}\;t\_3 \leq -1 \cdot 10^{-246}:\\
    \;\;\;\;c0 \cdot \frac{\frac{1}{\frac{h}{2 \cdot \frac{c0 \cdot t\_1}{w}}}}{2 \cdot w}\\
    
    \mathbf{elif}\;t\_3 \leq 0:\\
    \;\;\;\;c0 \cdot \frac{\frac{{M}^{2}}{t\_0 + t\_1 \cdot \frac{c0}{w \cdot h}}}{2 \cdot w}\\
    
    \mathbf{elif}\;t\_3 \leq \infty:\\
    \;\;\;\;c0 \cdot \frac{2 \cdot t\_0}{2 \cdot w}\\
    
    \mathbf{else}:\\
    \;\;\;\;c0 \cdot \frac{0}{2 \cdot w}\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 4 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))))) < -9.99999999999999956e-247

      1. Initial program 87.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. Simplified80.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 \left(c0 \cdot \left(d \cdot \frac{d}{D \cdot \left(w \cdot \left(h \cdot D\right)\right)}\right) - M\right)}\right)}{2 \cdot w}} \]
      3. Add Preprocessing
      4. Taylor expanded in h around 0 16.6%

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

          \[\leadsto c0 \cdot \frac{\color{blue}{\frac{\mathsf{fma}\left(0.5, {D}^{2} \cdot \left(h \cdot \frac{w \cdot 0}{c0 \cdot {d}^{2}}\right), 2 \cdot \frac{\frac{c0 \cdot {d}^{2}}{{D}^{2}}}{w}\right)}{h}}}{2 \cdot w} \]
        2. Taylor expanded in w around 0 87.5%

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

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

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

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

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

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

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

        if -9.99999999999999956e-247 < (*.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))))) < -0.0

        1. Initial program 33.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. Simplified12.7%

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

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

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

            \[\leadsto c0 \cdot \frac{\frac{\color{blue}{0} + {M}^{2}}{\frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2} - \sqrt{{\left(\frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2}\right)}^{2} - {M}^{2}}}}{2 \cdot w} \]
          3. associate-*l/57.8%

            \[\leadsto c0 \cdot \frac{\frac{0 + {M}^{2}}{\color{blue}{\frac{c0 \cdot {\left(\frac{d}{D}\right)}^{2}}{w \cdot h}} - \sqrt{{\left(\frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2}\right)}^{2} - {M}^{2}}}}{2 \cdot w} \]
          4. associate-/l*58.2%

            \[\leadsto c0 \cdot \frac{\frac{0 + {M}^{2}}{\color{blue}{c0 \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{w \cdot h}} - \sqrt{{\left(\frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2}\right)}^{2} - {M}^{2}}}}{2 \cdot w} \]
          5. *-commutative58.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

            \[\leadsto c0 \cdot \frac{\frac{{M}^{2}}{\frac{c0}{h \cdot w} \cdot {\left(\frac{d}{D}\right)}^{2} - \sqrt{\color{blue}{{\left(\frac{\frac{c0}{w}}{h}\right)}^{2} \cdot {\left(\frac{d}{D}\right)}^{4} - {M}^{2}}}}}{2 \cdot w} \]
          5. associate-/l/47.8%

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

          \[\leadsto c0 \cdot \frac{\color{blue}{\frac{{M}^{2}}{\frac{c0}{h \cdot w} \cdot {\left(\frac{d}{D}\right)}^{2} - \sqrt{{\left(\frac{c0}{h \cdot w}\right)}^{2} \cdot {\left(\frac{d}{D}\right)}^{4} - {M}^{2}}}}}{2 \cdot w} \]
        11. Taylor expanded in c0 around -inf 68.0%

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

            \[\leadsto c0 \cdot \frac{\frac{{M}^{2}}{\frac{c0}{h \cdot w} \cdot {\left(\frac{d}{D}\right)}^{2} - -1 \cdot \frac{c0 \cdot {d}^{2}}{{D}^{2} \cdot \color{blue}{\left(w \cdot h\right)}}}}{2 \cdot w} \]
          2. neg-mul-168.0%

            \[\leadsto c0 \cdot \frac{\frac{{M}^{2}}{\frac{c0}{h \cdot w} \cdot {\left(\frac{d}{D}\right)}^{2} - \color{blue}{\left(-\frac{c0 \cdot {d}^{2}}{{D}^{2} \cdot \left(w \cdot h\right)}\right)}}}{2 \cdot w} \]
          3. distribute-neg-frac268.0%

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

            \[\leadsto c0 \cdot \frac{\frac{{M}^{2}}{\frac{c0}{h \cdot w} \cdot {\left(\frac{d}{D}\right)}^{2} - \frac{c0 \cdot {d}^{2}}{-{D}^{2} \cdot \color{blue}{\left(h \cdot w\right)}}}}{2 \cdot w} \]
        13. Simplified68.0%

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

        if -0.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))))) < +inf.0

        1. Initial program 73.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. Simplified73.5%

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

          \[\leadsto c0 \cdot \frac{\color{blue}{2 \cdot \frac{c0 \cdot {d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}}}{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. Simplified18.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      Alternative 3: 53.8% accurate, 0.4× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{c0 \cdot \left(d \cdot d\right)}{\left(D \cdot D\right) \cdot \left(w \cdot h\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{2 \cdot \frac{c0 \cdot {d}^{2}}{\left(w \cdot h\right) \cdot {D}^{2}}}{2 \cdot w}\\ \mathbf{else}:\\ \;\;\;\;c0 \cdot \frac{0}{2 \cdot w}\\ \end{array} \end{array} \]
      (FPCore (c0 w h D d M)
       :precision binary64
       (let* ((t_0 (/ (* c0 (* d d)) (* (* D D) (* w h)))))
         (if (<=
              (* (/ c0 (* 2.0 w)) (+ t_0 (sqrt (- (* t_0 t_0) (* M M)))))
              INFINITY)
           (*
            c0
            (/ (* 2.0 (/ (* c0 (pow d 2.0)) (* (* w h) (pow D 2.0)))) (* 2.0 w)))
           (* c0 (/ 0.0 (* 2.0 w))))))
      double code(double c0, double w, double h, double D, double d, double M) {
      	double t_0 = (c0 * (d * d)) / ((D * D) * (w * h));
      	double tmp;
      	if (((c0 / (2.0 * w)) * (t_0 + sqrt(((t_0 * t_0) - (M * M))))) <= ((double) INFINITY)) {
      		tmp = c0 * ((2.0 * ((c0 * pow(d, 2.0)) / ((w * h) * pow(D, 2.0)))) / (2.0 * w));
      	} else {
      		tmp = c0 * (0.0 / (2.0 * w));
      	}
      	return tmp;
      }
      
      public static double code(double c0, double w, double h, double D, double d, double M) {
      	double t_0 = (c0 * (d * d)) / ((D * D) * (w * h));
      	double tmp;
      	if (((c0 / (2.0 * w)) * (t_0 + Math.sqrt(((t_0 * t_0) - (M * M))))) <= Double.POSITIVE_INFINITY) {
      		tmp = c0 * ((2.0 * ((c0 * Math.pow(d, 2.0)) / ((w * h) * Math.pow(D, 2.0)))) / (2.0 * w));
      	} else {
      		tmp = c0 * (0.0 / (2.0 * w));
      	}
      	return tmp;
      }
      
      def code(c0, w, h, D, d, M):
      	t_0 = (c0 * (d * d)) / ((D * D) * (w * h))
      	tmp = 0
      	if ((c0 / (2.0 * w)) * (t_0 + math.sqrt(((t_0 * t_0) - (M * M))))) <= math.inf:
      		tmp = c0 * ((2.0 * ((c0 * math.pow(d, 2.0)) / ((w * h) * math.pow(D, 2.0)))) / (2.0 * w))
      	else:
      		tmp = c0 * (0.0 / (2.0 * w))
      	return tmp
      
      function code(c0, w, h, D, d, M)
      	t_0 = Float64(Float64(c0 * Float64(d * d)) / Float64(Float64(D * D) * Float64(w * h)))
      	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(2.0 * Float64(Float64(c0 * (d ^ 2.0)) / Float64(Float64(w * h) * (D ^ 2.0)))) / Float64(2.0 * w)));
      	else
      		tmp = Float64(c0 * Float64(0.0 / Float64(2.0 * w)));
      	end
      	return tmp
      end
      
      function tmp_2 = code(c0, w, h, D, d, M)
      	t_0 = (c0 * (d * d)) / ((D * D) * (w * h));
      	tmp = 0.0;
      	if (((c0 / (2.0 * w)) * (t_0 + sqrt(((t_0 * t_0) - (M * M))))) <= Inf)
      		tmp = c0 * ((2.0 * ((c0 * (d ^ 2.0)) / ((w * h) * (D ^ 2.0)))) / (2.0 * w));
      	else
      		tmp = c0 * (0.0 / (2.0 * w));
      	end
      	tmp_2 = tmp;
      end
      
      code[c0_, w_, h_, D_, d_, M_] := Block[{t$95$0 = N[(N[(c0 * N[(d * d), $MachinePrecision]), $MachinePrecision] / N[(N[(D * D), $MachinePrecision] * N[(w * h), $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[(2.0 * N[(N[(c0 * N[Power[d, 2.0], $MachinePrecision]), $MachinePrecision] / N[(N[(w * h), $MachinePrecision] * N[Power[D, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(2.0 * w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(c0 * N[(0.0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      t_0 := \frac{c0 \cdot \left(d \cdot d\right)}{\left(D \cdot D\right) \cdot \left(w \cdot h\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{2 \cdot \frac{c0 \cdot {d}^{2}}{\left(w \cdot h\right) \cdot {D}^{2}}}{2 \cdot w}\\
      
      \mathbf{else}:\\
      \;\;\;\;c0 \cdot \frac{0}{2 \cdot w}\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if (*.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 73.8%

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

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

          \[\leadsto c0 \cdot \frac{\color{blue}{2 \cdot \frac{c0 \cdot {d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}}}{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. Simplified18.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      Alternative 4: 53.8% accurate, 0.6× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{c0 \cdot \left(d \cdot d\right)}{\left(D \cdot D\right) \cdot \left(w \cdot h\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{2 \cdot \frac{c0 \cdot {\left(\frac{d}{D}\right)}^{2}}{w \cdot h}}{2 \cdot w}\\ \mathbf{else}:\\ \;\;\;\;c0 \cdot \frac{0}{2 \cdot w}\\ \end{array} \end{array} \]
      (FPCore (c0 w h D d M)
       :precision binary64
       (let* ((t_0 (/ (* c0 (* d d)) (* (* D D) (* w h)))))
         (if (<=
              (* (/ c0 (* 2.0 w)) (+ t_0 (sqrt (- (* t_0 t_0) (* M M)))))
              INFINITY)
           (* c0 (/ (* 2.0 (/ (* c0 (pow (/ d D) 2.0)) (* w h))) (* 2.0 w)))
           (* c0 (/ 0.0 (* 2.0 w))))))
      double code(double c0, double w, double h, double D, double d, double M) {
      	double t_0 = (c0 * (d * d)) / ((D * D) * (w * h));
      	double tmp;
      	if (((c0 / (2.0 * w)) * (t_0 + sqrt(((t_0 * t_0) - (M * M))))) <= ((double) INFINITY)) {
      		tmp = c0 * ((2.0 * ((c0 * pow((d / D), 2.0)) / (w * h))) / (2.0 * w));
      	} else {
      		tmp = c0 * (0.0 / (2.0 * w));
      	}
      	return tmp;
      }
      
      public static double code(double c0, double w, double h, double D, double d, double M) {
      	double t_0 = (c0 * (d * d)) / ((D * D) * (w * h));
      	double tmp;
      	if (((c0 / (2.0 * w)) * (t_0 + Math.sqrt(((t_0 * t_0) - (M * M))))) <= Double.POSITIVE_INFINITY) {
      		tmp = c0 * ((2.0 * ((c0 * Math.pow((d / D), 2.0)) / (w * h))) / (2.0 * w));
      	} else {
      		tmp = c0 * (0.0 / (2.0 * w));
      	}
      	return tmp;
      }
      
      def code(c0, w, h, D, d, M):
      	t_0 = (c0 * (d * d)) / ((D * D) * (w * h))
      	tmp = 0
      	if ((c0 / (2.0 * w)) * (t_0 + math.sqrt(((t_0 * t_0) - (M * M))))) <= math.inf:
      		tmp = c0 * ((2.0 * ((c0 * math.pow((d / D), 2.0)) / (w * h))) / (2.0 * w))
      	else:
      		tmp = c0 * (0.0 / (2.0 * w))
      	return tmp
      
      function code(c0, w, h, D, d, M)
      	t_0 = Float64(Float64(c0 * Float64(d * d)) / Float64(Float64(D * D) * Float64(w * h)))
      	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(2.0 * Float64(Float64(c0 * (Float64(d / D) ^ 2.0)) / Float64(w * h))) / Float64(2.0 * w)));
      	else
      		tmp = Float64(c0 * Float64(0.0 / Float64(2.0 * w)));
      	end
      	return tmp
      end
      
      function tmp_2 = code(c0, w, h, D, d, M)
      	t_0 = (c0 * (d * d)) / ((D * D) * (w * h));
      	tmp = 0.0;
      	if (((c0 / (2.0 * w)) * (t_0 + sqrt(((t_0 * t_0) - (M * M))))) <= Inf)
      		tmp = c0 * ((2.0 * ((c0 * ((d / D) ^ 2.0)) / (w * h))) / (2.0 * w));
      	else
      		tmp = c0 * (0.0 / (2.0 * w));
      	end
      	tmp_2 = tmp;
      end
      
      code[c0_, w_, h_, D_, d_, M_] := Block[{t$95$0 = N[(N[(c0 * N[(d * d), $MachinePrecision]), $MachinePrecision] / N[(N[(D * D), $MachinePrecision] * N[(w * h), $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[(2.0 * N[(N[(c0 * N[Power[N[(d / D), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / N[(w * h), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(2.0 * w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(c0 * N[(0.0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      t_0 := \frac{c0 \cdot \left(d \cdot d\right)}{\left(D \cdot D\right) \cdot \left(w \cdot h\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{2 \cdot \frac{c0 \cdot {\left(\frac{d}{D}\right)}^{2}}{w \cdot h}}{2 \cdot w}\\
      
      \mathbf{else}:\\
      \;\;\;\;c0 \cdot \frac{0}{2 \cdot w}\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if (*.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 73.8%

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

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

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

            \[\leadsto c0 \cdot \frac{\color{blue}{\frac{\mathsf{fma}\left(0.5, {D}^{2} \cdot \left(h \cdot \frac{w \cdot 0}{c0 \cdot {d}^{2}}\right), 2 \cdot \frac{\frac{c0 \cdot {d}^{2}}{{D}^{2}}}{w}\right)}{h}}}{2 \cdot w} \]
          2. Taylor expanded in w around 0 74.7%

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

              \[\leadsto c0 \cdot \frac{\color{blue}{\mathsf{fma}\left(0.5, {D}^{2} \cdot \left(h \cdot 0\right), 2 \cdot \frac{\frac{c0 \cdot {d}^{2}}{{D}^{2}}}{w}\right) \cdot \frac{1}{h}}}{2 \cdot w} \]
          4. Applied egg-rr74.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            \[\leadsto c0 \cdot \frac{2 \cdot \color{blue}{\frac{c0 \cdot {\left(\frac{d}{D}\right)}^{2}}{w \cdot h}}}{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. Simplified18.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        Alternative 5: 42.5% accurate, 1.3× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;w \leq 1.16 \cdot 10^{-32}:\\ \;\;\;\;c0 \cdot \left({\left(\frac{d}{D}\right)}^{2} \cdot \frac{\frac{c0}{w \cdot h}}{w}\right)\\ \mathbf{else}:\\ \;\;\;\;c0 \cdot \frac{0}{2 \cdot w}\\ \end{array} \end{array} \]
        (FPCore (c0 w h D d M)
         :precision binary64
         (if (<= w 1.16e-32)
           (* c0 (* (pow (/ d D) 2.0) (/ (/ c0 (* w h)) w)))
           (* c0 (/ 0.0 (* 2.0 w)))))
        double code(double c0, double w, double h, double D, double d, double M) {
        	double tmp;
        	if (w <= 1.16e-32) {
        		tmp = c0 * (pow((d / D), 2.0) * ((c0 / (w * h)) / w));
        	} else {
        		tmp = c0 * (0.0 / (2.0 * w));
        	}
        	return tmp;
        }
        
        real(8) function code(c0, w, h, d, d_1, m)
            real(8), intent (in) :: c0
            real(8), intent (in) :: w
            real(8), intent (in) :: h
            real(8), intent (in) :: d
            real(8), intent (in) :: d_1
            real(8), intent (in) :: m
            real(8) :: tmp
            if (w <= 1.16d-32) then
                tmp = c0 * (((d_1 / d) ** 2.0d0) * ((c0 / (w * h)) / w))
            else
                tmp = c0 * (0.0d0 / (2.0d0 * w))
            end if
            code = tmp
        end function
        
        public static double code(double c0, double w, double h, double D, double d, double M) {
        	double tmp;
        	if (w <= 1.16e-32) {
        		tmp = c0 * (Math.pow((d / D), 2.0) * ((c0 / (w * h)) / w));
        	} else {
        		tmp = c0 * (0.0 / (2.0 * w));
        	}
        	return tmp;
        }
        
        def code(c0, w, h, D, d, M):
        	tmp = 0
        	if w <= 1.16e-32:
        		tmp = c0 * (math.pow((d / D), 2.0) * ((c0 / (w * h)) / w))
        	else:
        		tmp = c0 * (0.0 / (2.0 * w))
        	return tmp
        
        function code(c0, w, h, D, d, M)
        	tmp = 0.0
        	if (w <= 1.16e-32)
        		tmp = Float64(c0 * Float64((Float64(d / D) ^ 2.0) * Float64(Float64(c0 / Float64(w * h)) / w)));
        	else
        		tmp = Float64(c0 * Float64(0.0 / Float64(2.0 * w)));
        	end
        	return tmp
        end
        
        function tmp_2 = code(c0, w, h, D, d, M)
        	tmp = 0.0;
        	if (w <= 1.16e-32)
        		tmp = c0 * (((d / D) ^ 2.0) * ((c0 / (w * h)) / w));
        	else
        		tmp = c0 * (0.0 / (2.0 * w));
        	end
        	tmp_2 = tmp;
        end
        
        code[c0_, w_, h_, D_, d_, M_] := If[LessEqual[w, 1.16e-32], N[(c0 * N[(N[Power[N[(d / D), $MachinePrecision], 2.0], $MachinePrecision] * N[(N[(c0 / N[(w * h), $MachinePrecision]), $MachinePrecision] / w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(c0 * N[(0.0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        \mathbf{if}\;w \leq 1.16 \cdot 10^{-32}:\\
        \;\;\;\;c0 \cdot \left({\left(\frac{d}{D}\right)}^{2} \cdot \frac{\frac{c0}{w \cdot h}}{w}\right)\\
        
        \mathbf{else}:\\
        \;\;\;\;c0 \cdot \frac{0}{2 \cdot w}\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if w < 1.16000000000000001e-32

          1. Initial program 23.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. Simplified36.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
          4. Taylor expanded in h around 0 7.7%

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

              \[\leadsto c0 \cdot \frac{\color{blue}{\frac{\mathsf{fma}\left(0.5, {D}^{2} \cdot \left(h \cdot \frac{w \cdot 0}{c0 \cdot {d}^{2}}\right), 2 \cdot \frac{\frac{c0 \cdot {d}^{2}}{{D}^{2}}}{w}\right)}{h}}}{2 \cdot w} \]
            2. Taylor expanded in w around 0 33.1%

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

                \[\leadsto c0 \cdot \frac{\color{blue}{\mathsf{fma}\left(0.5, {D}^{2} \cdot \left(h \cdot 0\right), 2 \cdot \frac{\frac{c0 \cdot {d}^{2}}{{D}^{2}}}{w}\right) \cdot \frac{1}{h}}}{2 \cdot w} \]
            4. Applied egg-rr44.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            if 1.16000000000000001e-32 < w

            1. Initial program 15.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. Simplified21.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

            \[\leadsto \begin{array}{l} \mathbf{if}\;w \leq 1.16 \cdot 10^{-32}:\\ \;\;\;\;c0 \cdot \left({\left(\frac{d}{D}\right)}^{2} \cdot \frac{\frac{c0}{w \cdot h}}{w}\right)\\ \mathbf{else}:\\ \;\;\;\;c0 \cdot \frac{0}{2 \cdot w}\\ \end{array} \]
          8. Add Preprocessing

          Alternative 6: 43.9% accurate, 1.3× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;w \leq 3.6 \cdot 10^{+162}:\\ \;\;\;\;c0 \cdot \frac{{\left(\frac{d}{D}\right)}^{2} \cdot \frac{c0}{w \cdot h}}{w}\\ \mathbf{else}:\\ \;\;\;\;c0 \cdot \frac{0}{2 \cdot w}\\ \end{array} \end{array} \]
          (FPCore (c0 w h D d M)
           :precision binary64
           (if (<= w 3.6e+162)
             (* c0 (/ (* (pow (/ d D) 2.0) (/ c0 (* w h))) w))
             (* c0 (/ 0.0 (* 2.0 w)))))
          double code(double c0, double w, double h, double D, double d, double M) {
          	double tmp;
          	if (w <= 3.6e+162) {
          		tmp = c0 * ((pow((d / D), 2.0) * (c0 / (w * h))) / w);
          	} else {
          		tmp = c0 * (0.0 / (2.0 * w));
          	}
          	return tmp;
          }
          
          real(8) function code(c0, w, h, d, d_1, m)
              real(8), intent (in) :: c0
              real(8), intent (in) :: w
              real(8), intent (in) :: h
              real(8), intent (in) :: d
              real(8), intent (in) :: d_1
              real(8), intent (in) :: m
              real(8) :: tmp
              if (w <= 3.6d+162) then
                  tmp = c0 * ((((d_1 / d) ** 2.0d0) * (c0 / (w * h))) / w)
              else
                  tmp = c0 * (0.0d0 / (2.0d0 * w))
              end if
              code = tmp
          end function
          
          public static double code(double c0, double w, double h, double D, double d, double M) {
          	double tmp;
          	if (w <= 3.6e+162) {
          		tmp = c0 * ((Math.pow((d / D), 2.0) * (c0 / (w * h))) / w);
          	} else {
          		tmp = c0 * (0.0 / (2.0 * w));
          	}
          	return tmp;
          }
          
          def code(c0, w, h, D, d, M):
          	tmp = 0
          	if w <= 3.6e+162:
          		tmp = c0 * ((math.pow((d / D), 2.0) * (c0 / (w * h))) / w)
          	else:
          		tmp = c0 * (0.0 / (2.0 * w))
          	return tmp
          
          function code(c0, w, h, D, d, M)
          	tmp = 0.0
          	if (w <= 3.6e+162)
          		tmp = Float64(c0 * Float64(Float64((Float64(d / D) ^ 2.0) * Float64(c0 / Float64(w * h))) / w));
          	else
          		tmp = Float64(c0 * Float64(0.0 / Float64(2.0 * w)));
          	end
          	return tmp
          end
          
          function tmp_2 = code(c0, w, h, D, d, M)
          	tmp = 0.0;
          	if (w <= 3.6e+162)
          		tmp = c0 * ((((d / D) ^ 2.0) * (c0 / (w * h))) / w);
          	else
          		tmp = c0 * (0.0 / (2.0 * w));
          	end
          	tmp_2 = tmp;
          end
          
          code[c0_, w_, h_, D_, d_, M_] := If[LessEqual[w, 3.6e+162], N[(c0 * N[(N[(N[Power[N[(d / D), $MachinePrecision], 2.0], $MachinePrecision] * N[(c0 / N[(w * h), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / w), $MachinePrecision]), $MachinePrecision], N[(c0 * N[(0.0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          \mathbf{if}\;w \leq 3.6 \cdot 10^{+162}:\\
          \;\;\;\;c0 \cdot \frac{{\left(\frac{d}{D}\right)}^{2} \cdot \frac{c0}{w \cdot h}}{w}\\
          
          \mathbf{else}:\\
          \;\;\;\;c0 \cdot \frac{0}{2 \cdot w}\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if w < 3.59999999999999994e162

            1. Initial program 22.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. Simplified34.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
            4. Taylor expanded in h around 0 7.6%

              \[\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)}{{D}^{2} \cdot w} + \frac{M \cdot \left(c0 \cdot {d}^{2}\right)}{{D}^{2} \cdot w}\right)\right)\right)}{c0 \cdot {d}^{2}} + 2 \cdot \frac{c0 \cdot {d}^{2}}{{D}^{2} \cdot w}}{h}}}{2 \cdot w} \]
            5. Step-by-step derivation
              1. Simplified31.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

              if 3.59999999999999994e162 < w

              1. Initial program 13.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

              \[\leadsto \begin{array}{l} \mathbf{if}\;w \leq 3.6 \cdot 10^{+162}:\\ \;\;\;\;c0 \cdot \frac{{\left(\frac{d}{D}\right)}^{2} \cdot \frac{c0}{w \cdot h}}{w}\\ \mathbf{else}:\\ \;\;\;\;c0 \cdot \frac{0}{2 \cdot w}\\ \end{array} \]
            8. Add Preprocessing

            Alternative 7: 32.8% accurate, 21.6× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

              \[\leadsto c0 \cdot \frac{\color{blue}{0}}{2 \cdot w} \]
            7. Final simplification27.8%

              \[\leadsto c0 \cdot \frac{0}{2 \cdot w} \]
            8. Add Preprocessing

            Reproduce

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