Henrywood and Agarwal, Equation (13)

Percentage Accurate: 24.5% → 54.4%
Time: 31.5s
Alternatives: 5
Speedup: 16.8×

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 5 alternatives:

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

Initial Program: 24.5% 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.4% accurate, 0.2× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;\frac{c0 \cdot \left(c0 \cdot 0\right)}{2 \cdot w}\\


\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 80.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. Simplified79.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)} \]
    3. Add Preprocessing
    4. Step-by-step derivation
      1. associate-*l/79.6%

        \[\leadsto \color{blue}{\frac{c0 \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)}{2 \cdot w}} \]
    5. Applied egg-rr77.3%

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

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

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

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

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

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

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

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

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

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

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

    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. Simplified1.2%

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

        \[\leadsto \color{blue}{\frac{c0 \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)}{2 \cdot w}} \]
    5. Applied egg-rr6.7%

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

      \[\leadsto \frac{c0 \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)\right)}}{w \cdot 2} \]
    7. Step-by-step derivation
      1. associate-*r*1.8%

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

        \[\leadsto \frac{c0 \cdot \left(\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)}{w \cdot 2} \]
      3. distribute-lft1-in1.8%

        \[\leadsto \frac{c0 \cdot \left(\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)}{w \cdot 2} \]
      4. metadata-eval1.8%

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

        \[\leadsto \frac{c0 \cdot \left(\left(-c0\right) \cdot \color{blue}{0}\right)}{w \cdot 2} \]
      6. distribute-lft-neg-in46.8%

        \[\leadsto \frac{c0 \cdot \color{blue}{\left(-c0 \cdot 0\right)}}{w \cdot 2} \]
      7. distribute-rgt-neg-in46.8%

        \[\leadsto \frac{c0 \cdot \color{blue}{\left(c0 \cdot \left(-0\right)\right)}}{w \cdot 2} \]
      8. metadata-eval46.8%

        \[\leadsto \frac{c0 \cdot \left(c0 \cdot \color{blue}{0}\right)}{w \cdot 2} \]
    8. Simplified46.8%

      \[\leadsto \frac{c0 \cdot \color{blue}{\left(c0 \cdot 0\right)}}{w \cdot 2} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification58.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 \left({\left(\frac{d}{D}\right)}^{2} \cdot \frac{\frac{c0}{w}}{h} + \sqrt{{\left({\left(\frac{d}{D}\right)}^{2} \cdot \frac{\frac{c0}{w}}{h}\right)}^{2} - {M}^{2}}\right)}{2 \cdot w}\\ \mathbf{else}:\\ \;\;\;\;\frac{c0 \cdot \left(c0 \cdot 0\right)}{2 \cdot w}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 54.1% accurate, 0.3× speedup?

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

\\
\begin{array}{l}
t_0 := \frac{c0}{2 \cdot w}\\
t_1 := \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}\\
\mathbf{if}\;t\_0 \cdot \left(t\_1 + \sqrt{t\_1 \cdot t\_1 - M \cdot M}\right) \leq \infty:\\
\;\;\;\;t\_0 \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{\frac{c0}{w}}{h}\right)}^{2} - M \cdot M}\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{c0 \cdot \left(c0 \cdot 0\right)}{2 \cdot w}\\


\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 80.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. Simplified79.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)} \]
    3. Add Preprocessing
    4. Step-by-step derivation
      1. times-frac76.3%

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

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

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

        \[\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. associate-/r*76.3%

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

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

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

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

        \[\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}\right)}}^{2} \cdot {\left({\left(\frac{d}{D}\right)}^{2}\right)}^{2} + \left(-M\right) \cdot M}\right) \]
      8. unpow-prod-down83.4%

        \[\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) \]
      9. *-commutative83.4%

        \[\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({\left(\frac{d}{D}\right)}^{2} \cdot \frac{c0}{w \cdot h}\right)}}^{2} + \left(-M\right) \cdot M}\right) \]
      10. associate-/r*83.3%

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

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

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

        \[\leadsto \color{blue}{\frac{c0 \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)}{2 \cdot w}} \]
    5. Applied egg-rr6.7%

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

      \[\leadsto \frac{c0 \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)\right)}}{w \cdot 2} \]
    7. Step-by-step derivation
      1. associate-*r*1.8%

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

        \[\leadsto \frac{c0 \cdot \left(\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)}{w \cdot 2} \]
      3. distribute-lft1-in1.8%

        \[\leadsto \frac{c0 \cdot \left(\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)}{w \cdot 2} \]
      4. metadata-eval1.8%

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

        \[\leadsto \frac{c0 \cdot \left(\left(-c0\right) \cdot \color{blue}{0}\right)}{w \cdot 2} \]
      6. distribute-lft-neg-in46.8%

        \[\leadsto \frac{c0 \cdot \color{blue}{\left(-c0 \cdot 0\right)}}{w \cdot 2} \]
      7. distribute-rgt-neg-in46.8%

        \[\leadsto \frac{c0 \cdot \color{blue}{\left(c0 \cdot \left(-0\right)\right)}}{w \cdot 2} \]
      8. metadata-eval46.8%

        \[\leadsto \frac{c0 \cdot \left(c0 \cdot \color{blue}{0}\right)}{w \cdot 2} \]
    8. Simplified46.8%

      \[\leadsto \frac{c0 \cdot \color{blue}{\left(c0 \cdot 0\right)}}{w \cdot 2} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification58.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}{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{\frac{c0}{w}}{h}\right)}^{2} - M \cdot M}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{c0 \cdot \left(c0 \cdot 0\right)}{2 \cdot w}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 54.6% accurate, 0.5× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;\frac{c0 \cdot \left(c0 \cdot 0\right)}{2 \cdot w}\\


\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 80.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. Add Preprocessing

    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. Simplified1.2%

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

        \[\leadsto \color{blue}{\frac{c0 \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)}{2 \cdot w}} \]
    5. Applied egg-rr6.7%

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

      \[\leadsto \frac{c0 \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)\right)}}{w \cdot 2} \]
    7. Step-by-step derivation
      1. associate-*r*1.8%

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

        \[\leadsto \frac{c0 \cdot \left(\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)}{w \cdot 2} \]
      3. distribute-lft1-in1.8%

        \[\leadsto \frac{c0 \cdot \left(\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)}{w \cdot 2} \]
      4. metadata-eval1.8%

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

        \[\leadsto \frac{c0 \cdot \left(\left(-c0\right) \cdot \color{blue}{0}\right)}{w \cdot 2} \]
      6. distribute-lft-neg-in46.8%

        \[\leadsto \frac{c0 \cdot \color{blue}{\left(-c0 \cdot 0\right)}}{w \cdot 2} \]
      7. distribute-rgt-neg-in46.8%

        \[\leadsto \frac{c0 \cdot \color{blue}{\left(c0 \cdot \left(-0\right)\right)}}{w \cdot 2} \]
      8. metadata-eval46.8%

        \[\leadsto \frac{c0 \cdot \left(c0 \cdot \color{blue}{0}\right)}{w \cdot 2} \]
    8. Simplified46.8%

      \[\leadsto \frac{c0 \cdot \color{blue}{\left(c0 \cdot 0\right)}}{w \cdot 2} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification57.5%

    \[\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 \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)\\ \mathbf{else}:\\ \;\;\;\;\frac{c0 \cdot \left(c0 \cdot 0\right)}{2 \cdot w}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 37.4% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;D \leq 2.35 \cdot 10^{-189} \lor \neg \left(D \leq 9.8 \cdot 10^{-166}\right) \land \left(D \leq 1.75 \cdot 10^{-155} \lor \neg \left(D \leq 5.8 \cdot 10^{-87}\right) \land D \leq 4.3 \cdot 10^{-32}\right):\\
\;\;\;\;\frac{c0 \cdot \left(c0 \cdot 0\right)}{2 \cdot w}\\

\mathbf{else}:\\
\;\;\;\;c0 \cdot \frac{2 \cdot \left({\left(\frac{d}{D}\right)}^{2} \cdot \frac{c0}{w \cdot h}\right)}{2 \cdot w}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if D < 2.3499999999999998e-189 or 9.7999999999999998e-166 < D < 1.75000000000000008e-155 or 5.7999999999999998e-87 < D < 4.2999999999999999e-32

    1. Initial program 19.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. Simplified19.8%

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

        \[\leadsto \color{blue}{\frac{c0 \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)}{2 \cdot w}} \]
    5. Applied egg-rr21.2%

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

      \[\leadsto \frac{c0 \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)\right)}}{w \cdot 2} \]
    7. Step-by-step derivation
      1. associate-*r*3.6%

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

        \[\leadsto \frac{c0 \cdot \left(\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)}{w \cdot 2} \]
      3. distribute-lft1-in3.6%

        \[\leadsto \frac{c0 \cdot \left(\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)}{w \cdot 2} \]
      4. metadata-eval3.6%

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

        \[\leadsto \frac{c0 \cdot \left(\left(-c0\right) \cdot \color{blue}{0}\right)}{w \cdot 2} \]
      6. distribute-lft-neg-in41.2%

        \[\leadsto \frac{c0 \cdot \color{blue}{\left(-c0 \cdot 0\right)}}{w \cdot 2} \]
      7. distribute-rgt-neg-in41.2%

        \[\leadsto \frac{c0 \cdot \color{blue}{\left(c0 \cdot \left(-0\right)\right)}}{w \cdot 2} \]
      8. metadata-eval41.2%

        \[\leadsto \frac{c0 \cdot \left(c0 \cdot \color{blue}{0}\right)}{w \cdot 2} \]
    8. Simplified41.2%

      \[\leadsto \frac{c0 \cdot \color{blue}{\left(c0 \cdot 0\right)}}{w \cdot 2} \]

    if 2.3499999999999998e-189 < D < 9.7999999999999998e-166 or 1.75000000000000008e-155 < D < 5.7999999999999998e-87 or 4.2999999999999999e-32 < D

    1. Initial program 37.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. Simplified47.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 46.5%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto c0 \cdot \frac{\mathsf{fma}\left(c0, d \cdot \frac{d}{D \cdot \left(w \cdot \left(h \cdot D\right)\right)}, c0 \cdot \color{blue}{\frac{{\left(\frac{d}{D}\right)}^{2}}{h \cdot w}}\right)}{2 \cdot w} \]
    10. Simplified51.4%

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

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

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

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

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

      \[\leadsto \color{blue}{c0 \cdot \frac{2 \cdot \left({\left(\frac{d}{D}\right)}^{2} \cdot \frac{c0}{h \cdot w}\right)}{2 \cdot w}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification45.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;D \leq 2.35 \cdot 10^{-189} \lor \neg \left(D \leq 9.8 \cdot 10^{-166}\right) \land \left(D \leq 1.75 \cdot 10^{-155} \lor \neg \left(D \leq 5.8 \cdot 10^{-87}\right) \land D \leq 4.3 \cdot 10^{-32}\right):\\ \;\;\;\;\frac{c0 \cdot \left(c0 \cdot 0\right)}{2 \cdot w}\\ \mathbf{else}:\\ \;\;\;\;c0 \cdot \frac{2 \cdot \left({\left(\frac{d}{D}\right)}^{2} \cdot \frac{c0}{w \cdot h}\right)}{2 \cdot w}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 33.6% accurate, 16.8× speedup?

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

\\
\frac{c0 \cdot \left(c0 \cdot 0\right)}{2 \cdot w}
\end{array}
Derivation
  1. Initial program 25.3%

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

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

      \[\leadsto \color{blue}{\frac{c0 \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)}{2 \cdot w}} \]
  5. Applied egg-rr28.7%

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

    \[\leadsto \frac{c0 \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)\right)}}{w \cdot 2} \]
  7. Step-by-step derivation
    1. associate-*r*5.0%

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

      \[\leadsto \frac{c0 \cdot \left(\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)}{w \cdot 2} \]
    3. distribute-lft1-in5.0%

      \[\leadsto \frac{c0 \cdot \left(\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)}{w \cdot 2} \]
    4. metadata-eval5.0%

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

      \[\leadsto \frac{c0 \cdot \left(\left(-c0\right) \cdot \color{blue}{0}\right)}{w \cdot 2} \]
    6. distribute-lft-neg-in36.6%

      \[\leadsto \frac{c0 \cdot \color{blue}{\left(-c0 \cdot 0\right)}}{w \cdot 2} \]
    7. distribute-rgt-neg-in36.6%

      \[\leadsto \frac{c0 \cdot \color{blue}{\left(c0 \cdot \left(-0\right)\right)}}{w \cdot 2} \]
    8. metadata-eval36.6%

      \[\leadsto \frac{c0 \cdot \left(c0 \cdot \color{blue}{0}\right)}{w \cdot 2} \]
  8. Simplified36.6%

    \[\leadsto \frac{c0 \cdot \color{blue}{\left(c0 \cdot 0\right)}}{w \cdot 2} \]
  9. Final simplification36.6%

    \[\leadsto \frac{c0 \cdot \left(c0 \cdot 0\right)}{2 \cdot w} \]
  10. Add Preprocessing

Reproduce

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