Henrywood and Agarwal, Equation (13)

Percentage Accurate: 25.0% → 55.5%
Time: 24.4s
Alternatives: 4
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 4 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 25.0% 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: 55.5% accurate, 0.1× speedup?

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

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

\mathbf{elif}\;t_5 \leq 0:\\
\;\;\;\;\frac{0.25 \cdot {D}^{2}}{\frac{{d}^{2}}{h \cdot {M}^{2}}}\\

\mathbf{elif}\;t_5 \leq \infty:\\
\;\;\;\;t_2 \cdot \mathsf{fma}\left(\sqrt{\mathsf{fma}\left(t_3, t_1, M\right)}, \sqrt{t_1 \cdot t_3 - M}, t_1 \cdot \left(\frac{c0}{w} \cdot \frac{1}{h}\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (*.f64 (/.f64 c0 (*.f64 2 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 69.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. Step-by-step derivation
      1. times-frac68.8%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(\color{blue}{\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}} + \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) \]
    3. Simplified72.3%

      \[\leadsto \color{blue}{\frac{c0}{2 \cdot w} \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D} + \sqrt{\left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\right) \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\right) - M \cdot M}\right)} \]
    4. Step-by-step derivation
      1. +-commutative72.3%

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

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

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

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

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

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

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

    if -inf.0 < (*.f64 (/.f64 c0 (*.f64 2 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 43.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. Step-by-step derivation
      1. times-frac43.9%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(\color{blue}{\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}} + \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) \]
    3. Simplified49.6%

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

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

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{\left(0.5 \cdot \frac{{D}^{2} \cdot \left({M}^{2} \cdot \left(h \cdot w\right)\right)}{c0 \cdot {d}^{2}} + -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)\right)} \]
      2. times-frac33.3%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(0.5 \cdot \color{blue}{\left(\frac{{D}^{2}}{c0} \cdot \frac{{M}^{2} \cdot \left(h \cdot w\right)}{{d}^{2}}\right)} + -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)\right) \]
      3. associate-*r*47.6%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(0.5 \cdot \left(\frac{{D}^{2}}{c0} \cdot \frac{\color{blue}{\left({M}^{2} \cdot h\right) \cdot w}}{{d}^{2}}\right) + -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)\right) \]
      4. *-commutative47.6%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(0.5 \cdot \left(\frac{{D}^{2}}{c0} \cdot \frac{\color{blue}{\left(h \cdot {M}^{2}\right)} \cdot w}{{d}^{2}}\right) + -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)\right) \]
      5. associate-*r*47.6%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(0.5 \cdot \left(\frac{{D}^{2}}{c0} \cdot \frac{\left(h \cdot {M}^{2}\right) \cdot w}{{d}^{2}}\right) + \color{blue}{\left(-1 \cdot c0\right) \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) \]
      6. mul-1-neg47.6%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(0.5 \cdot \left(\frac{{D}^{2}}{c0} \cdot \frac{\left(h \cdot {M}^{2}\right) \cdot w}{{d}^{2}}\right) + \color{blue}{\left(-c0\right)} \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) \]
      7. distribute-lft1-in47.6%

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

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

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(0.5 \cdot \left(\frac{{D}^{2}}{c0} \cdot \frac{\left(h \cdot {M}^{2}\right) \cdot w}{{d}^{2}}\right) + \left(-c0\right) \cdot \color{blue}{0}\right) \]
      10. distribute-lft-neg-in47.6%

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

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

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{\left(0.5 \cdot \left(\frac{{D}^{2}}{c0} \cdot \frac{\left(h \cdot {M}^{2}\right) \cdot w}{{d}^{2}}\right) + c0 \cdot 0\right)} \]
    7. Taylor expanded in c0 around 0 64.4%

      \[\leadsto \color{blue}{0.25 \cdot \frac{{D}^{2} \cdot \left({M}^{2} \cdot h\right)}{{d}^{2}}} \]
    8. Step-by-step derivation
      1. associate-/l*68.0%

        \[\leadsto 0.25 \cdot \color{blue}{\frac{{D}^{2}}{\frac{{d}^{2}}{{M}^{2} \cdot h}}} \]
      2. associate-*r/68.0%

        \[\leadsto \color{blue}{\frac{0.25 \cdot {D}^{2}}{\frac{{d}^{2}}{{M}^{2} \cdot h}}} \]
      3. *-commutative68.0%

        \[\leadsto \frac{0.25 \cdot {D}^{2}}{\frac{{d}^{2}}{\color{blue}{h \cdot {M}^{2}}}} \]
    9. Simplified68.0%

      \[\leadsto \color{blue}{\frac{0.25 \cdot {D}^{2}}{\frac{{d}^{2}}{h \cdot {M}^{2}}}} \]

    if 0.0 < (*.f64 (/.f64 c0 (*.f64 2 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 80.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. Step-by-step derivation
      1. times-frac78.0%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(\color{blue}{\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}} + \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) \]
    3. Simplified80.4%

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

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

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

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

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

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

    if +inf.0 < (*.f64 (/.f64 c0 (*.f64 2 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. Step-by-step derivation
      1. times-frac0.0%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(\color{blue}{\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}} + \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) \]
    3. Simplified2.9%

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

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

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

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

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

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

      \[\leadsto \frac{c0 \cdot 0.5}{\frac{w}{\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)}}} \]
    8. Step-by-step derivation
      1. mul-1-neg1.9%

        \[\leadsto \frac{c0 \cdot 0.5}{\frac{w}{\color{blue}{-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)}}} \]
      2. distribute-lft1-in1.9%

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

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

        \[\leadsto \frac{c0 \cdot 0.5}{\frac{w}{-c0 \cdot \color{blue}{0}}} \]
      5. mul0-rgt46.3%

        \[\leadsto \frac{c0 \cdot 0.5}{\frac{w}{-\color{blue}{0}}} \]
      6. metadata-eval46.3%

        \[\leadsto \frac{c0 \cdot 0.5}{\frac{w}{\color{blue}{0}}} \]
    9. Simplified46.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \leq -\infty:\\ \;\;\;\;\frac{c0}{2 \cdot w} \cdot \mathsf{fma}\left(\sqrt{\mathsf{fma}\left(\frac{\frac{c0}{w}}{h}, {\left(\frac{d}{D}\right)}^{2}, M\right)}, \sqrt{\mathsf{fma}\left(\frac{\frac{c0}{w}}{h}, {\left(\frac{d}{D}\right)}^{2}, -M\right)}, \frac{\frac{c0}{w}}{h} \cdot {\left(\frac{d}{D}\right)}^{2}\right)\\ \mathbf{elif}\;\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \leq 0:\\ \;\;\;\;\frac{0.25 \cdot {D}^{2}}{\frac{{d}^{2}}{h \cdot {M}^{2}}}\\ \mathbf{elif}\;\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \leq \infty:\\ \;\;\;\;\frac{c0}{2 \cdot w} \cdot \mathsf{fma}\left(\sqrt{\mathsf{fma}\left(\frac{c0}{w \cdot h}, {\left(\frac{d}{D}\right)}^{2}, M\right)}, \sqrt{{\left(\frac{d}{D}\right)}^{2} \cdot \frac{c0}{w \cdot h} - M}, {\left(\frac{d}{D}\right)}^{2} \cdot \left(\frac{c0}{w} \cdot \frac{1}{h}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{c0 \cdot 0.5}{\frac{w}{0}}\\ \end{array} \]

Alternative 2: 54.6% accurate, 0.3× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (/.f64 c0 (*.f64 2 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 70.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. Step-by-step derivation
      1. times-frac68.9%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(\color{blue}{\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}} + \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) \]
    3. Simplified72.3%

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

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

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(\frac{c0}{w \cdot h} \cdot \color{blue}{\left(\frac{d}{D} \cdot \frac{d}{D}\right)} + \sqrt{\left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\right) \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\right) - M \cdot M}\right) \]
    6. Step-by-step derivation
      1. cancel-sign-sub-inv70.7%

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

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

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

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

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

    if +inf.0 < (*.f64 (/.f64 c0 (*.f64 2 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. Step-by-step derivation
      1. times-frac0.0%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(\color{blue}{\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}} + \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) \]
    3. Simplified2.9%

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

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

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

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

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

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

      \[\leadsto \frac{c0 \cdot 0.5}{\frac{w}{\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)}}} \]
    8. Step-by-step derivation
      1. mul-1-neg1.9%

        \[\leadsto \frac{c0 \cdot 0.5}{\frac{w}{\color{blue}{-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)}}} \]
      2. distribute-lft1-in1.9%

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

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

        \[\leadsto \frac{c0 \cdot 0.5}{\frac{w}{-c0 \cdot \color{blue}{0}}} \]
      5. mul0-rgt46.3%

        \[\leadsto \frac{c0 \cdot 0.5}{\frac{w}{-\color{blue}{0}}} \]
      6. metadata-eval46.3%

        \[\leadsto \frac{c0 \cdot 0.5}{\frac{w}{\color{blue}{0}}} \]
    9. Simplified46.3%

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

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

Alternative 3: 54.5% accurate, 0.6× speedup?

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (/.f64 c0 (*.f64 2 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 70.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. Step-by-step derivation
      1. times-frac68.9%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(\color{blue}{\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}} + \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) \]
    3. Simplified72.3%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{c0 \cdot 0.5}{\frac{w}{2 \cdot \left(c0 \cdot \frac{\color{blue}{\frac{d}{D} \cdot \frac{d}{D}}}{w \cdot h}\right)}} \]
      7. unpow274.3%

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

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

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

    if +inf.0 < (*.f64 (/.f64 c0 (*.f64 2 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. Step-by-step derivation
      1. times-frac0.0%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(\color{blue}{\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}} + \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) \]
    3. Simplified2.9%

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

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

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

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

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

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

      \[\leadsto \frac{c0 \cdot 0.5}{\frac{w}{\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)}}} \]
    8. Step-by-step derivation
      1. mul-1-neg1.9%

        \[\leadsto \frac{c0 \cdot 0.5}{\frac{w}{\color{blue}{-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)}}} \]
      2. distribute-lft1-in1.9%

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

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

        \[\leadsto \frac{c0 \cdot 0.5}{\frac{w}{-c0 \cdot \color{blue}{0}}} \]
      5. mul0-rgt46.3%

        \[\leadsto \frac{c0 \cdot 0.5}{\frac{w}{-\color{blue}{0}}} \]
      6. metadata-eval46.3%

        \[\leadsto \frac{c0 \cdot 0.5}{\frac{w}{\color{blue}{0}}} \]
    9. Simplified46.3%

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

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

Alternative 4: 33.9% accurate, 21.6× speedup?

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

\\
\frac{c0 \cdot 0.5}{\frac{w}{0}}
\end{array}
Derivation
  1. Initial program 22.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. Step-by-step derivation
    1. times-frac21.8%

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(\color{blue}{\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}} + \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) \]
  3. Simplified24.9%

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

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

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

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

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

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

    \[\leadsto \frac{c0 \cdot 0.5}{\frac{w}{\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)}}} \]
  8. Step-by-step derivation
    1. mul-1-neg5.1%

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

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

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

      \[\leadsto \frac{c0 \cdot 0.5}{\frac{w}{-c0 \cdot \color{blue}{0}}} \]
    5. mul0-rgt36.2%

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

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

    \[\leadsto \frac{c0 \cdot 0.5}{\frac{w}{\color{blue}{0}}} \]
  10. Final simplification36.2%

    \[\leadsto \frac{c0 \cdot 0.5}{\frac{w}{0}} \]

Reproduce

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