Henrywood and Agarwal, Equation (13)

Percentage Accurate: 24.9% → 55.2%
Time: 30.7s
Alternatives: 6
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 6 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.9% 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.2% 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}:\\ \;\;\;\;c0 \cdot \frac{0}{2 \cdot w}\\ \end{array} \end{array} \]
(FPCore (c0 w h D d M)
 :precision binary64
 (let* ((t_0 (/ (* c0 (* d d)) (* (* 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 (/ 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 * (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 * (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 * (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(c0 * Float64(0.0 / Float64(2.0 * w)));
	end
	return tmp
end
function tmp_2 = code(c0, w, h, D, d, M)
	t_0 = (c0 * (d * d)) / ((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 * (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[(c0 * N[(0.0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{c0 \cdot \left(d \cdot d\right)}{\left(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}:\\
\;\;\;\;c0 \cdot \frac{0}{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 76.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. 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. Simplified21.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 33.6% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{c0}{w \cdot h}\\ t_1 := t\_0 \cdot \left(\frac{d}{D} \cdot \frac{d}{D}\right)\\ \mathbf{if}\;d \leq 5.4 \cdot 10^{-134} \lor \neg \left(d \leq 2.45 \cdot 10^{+97}\right) \land \left(d \leq 1.2 \cdot 10^{+133} \lor \neg \left(d \leq 1.45 \cdot 10^{+149}\right)\right):\\ \;\;\;\;c0 \cdot \frac{0}{2 \cdot w}\\ \mathbf{else}:\\ \;\;\;\;\frac{c0}{2 \cdot w} \cdot \left(t\_0 \cdot \frac{d \cdot d}{D \cdot D} + \sqrt{t\_1 \cdot t\_1 - M \cdot M}\right)\\ \end{array} \end{array} \]
(FPCore (c0 w h D d M)
 :precision binary64
 (let* ((t_0 (/ c0 (* w h))) (t_1 (* t_0 (* (/ d D) (/ d D)))))
   (if (or (<= d 5.4e-134)
           (and (not (<= d 2.45e+97))
                (or (<= d 1.2e+133) (not (<= d 1.45e+149)))))
     (* c0 (/ 0.0 (* 2.0 w)))
     (*
      (/ c0 (* 2.0 w))
      (+ (* t_0 (/ (* d d) (* D D))) (sqrt (- (* t_1 t_1) (* M M))))))))
double code(double c0, double w, double h, double D, double d, double M) {
	double t_0 = c0 / (w * h);
	double t_1 = t_0 * ((d / D) * (d / D));
	double tmp;
	if ((d <= 5.4e-134) || (!(d <= 2.45e+97) && ((d <= 1.2e+133) || !(d <= 1.45e+149)))) {
		tmp = c0 * (0.0 / (2.0 * w));
	} else {
		tmp = (c0 / (2.0 * w)) * ((t_0 * ((d * d) / (D * D))) + sqrt(((t_1 * t_1) - (M * M))));
	}
	return tmp;
}
real(8) function code(c0, w, h, d, d_1, m)
    real(8), intent (in) :: c0
    real(8), intent (in) :: w
    real(8), intent (in) :: h
    real(8), intent (in) :: d
    real(8), intent (in) :: d_1
    real(8), intent (in) :: m
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = c0 / (w * h)
    t_1 = t_0 * ((d_1 / d) * (d_1 / d))
    if ((d_1 <= 5.4d-134) .or. (.not. (d_1 <= 2.45d+97)) .and. (d_1 <= 1.2d+133) .or. (.not. (d_1 <= 1.45d+149))) then
        tmp = c0 * (0.0d0 / (2.0d0 * w))
    else
        tmp = (c0 / (2.0d0 * w)) * ((t_0 * ((d_1 * d_1) / (d * d))) + sqrt(((t_1 * t_1) - (m * m))))
    end if
    code = tmp
end function
public static double code(double c0, double w, double h, double D, double d, double M) {
	double t_0 = c0 / (w * h);
	double t_1 = t_0 * ((d / D) * (d / D));
	double tmp;
	if ((d <= 5.4e-134) || (!(d <= 2.45e+97) && ((d <= 1.2e+133) || !(d <= 1.45e+149)))) {
		tmp = c0 * (0.0 / (2.0 * w));
	} else {
		tmp = (c0 / (2.0 * w)) * ((t_0 * ((d * d) / (D * D))) + Math.sqrt(((t_1 * t_1) - (M * M))));
	}
	return tmp;
}
def code(c0, w, h, D, d, M):
	t_0 = c0 / (w * h)
	t_1 = t_0 * ((d / D) * (d / D))
	tmp = 0
	if (d <= 5.4e-134) or (not (d <= 2.45e+97) and ((d <= 1.2e+133) or not (d <= 1.45e+149))):
		tmp = c0 * (0.0 / (2.0 * w))
	else:
		tmp = (c0 / (2.0 * w)) * ((t_0 * ((d * d) / (D * D))) + math.sqrt(((t_1 * t_1) - (M * M))))
	return tmp
function code(c0, w, h, D, d, M)
	t_0 = Float64(c0 / Float64(w * h))
	t_1 = Float64(t_0 * Float64(Float64(d / D) * Float64(d / D)))
	tmp = 0.0
	if ((d <= 5.4e-134) || (!(d <= 2.45e+97) && ((d <= 1.2e+133) || !(d <= 1.45e+149))))
		tmp = Float64(c0 * Float64(0.0 / Float64(2.0 * w)));
	else
		tmp = Float64(Float64(c0 / Float64(2.0 * w)) * Float64(Float64(t_0 * Float64(Float64(d * d) / Float64(D * D))) + sqrt(Float64(Float64(t_1 * t_1) - Float64(M * M)))));
	end
	return tmp
end
function tmp_2 = code(c0, w, h, D, d, M)
	t_0 = c0 / (w * h);
	t_1 = t_0 * ((d / D) * (d / D));
	tmp = 0.0;
	if ((d <= 5.4e-134) || (~((d <= 2.45e+97)) && ((d <= 1.2e+133) || ~((d <= 1.45e+149)))))
		tmp = c0 * (0.0 / (2.0 * w));
	else
		tmp = (c0 / (2.0 * w)) * ((t_0 * ((d * d) / (D * D))) + sqrt(((t_1 * t_1) - (M * M))));
	end
	tmp_2 = tmp;
end
code[c0_, w_, h_, D_, d_, M_] := Block[{t$95$0 = N[(c0 / N[(w * h), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 * N[(N[(d / D), $MachinePrecision] * N[(d / D), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[d, 5.4e-134], And[N[Not[LessEqual[d, 2.45e+97]], $MachinePrecision], Or[LessEqual[d, 1.2e+133], N[Not[LessEqual[d, 1.45e+149]], $MachinePrecision]]]], N[(c0 * N[(0.0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision] * N[(N[(t$95$0 * N[(N[(d * d), $MachinePrecision] / N[(D * D), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[Sqrt[N[(N[(t$95$1 * t$95$1), $MachinePrecision] - N[(M * M), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{c0}{w \cdot h}\\
t_1 := t\_0 \cdot \left(\frac{d}{D} \cdot \frac{d}{D}\right)\\
\mathbf{if}\;d \leq 5.4 \cdot 10^{-134} \lor \neg \left(d \leq 2.45 \cdot 10^{+97}\right) \land \left(d \leq 1.2 \cdot 10^{+133} \lor \neg \left(d \leq 1.45 \cdot 10^{+149}\right)\right):\\
\;\;\;\;c0 \cdot \frac{0}{2 \cdot w}\\

\mathbf{else}:\\
\;\;\;\;\frac{c0}{2 \cdot w} \cdot \left(t\_0 \cdot \frac{d \cdot d}{D \cdot D} + \sqrt{t\_1 \cdot t\_1 - M \cdot M}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < 5.3999999999999996e-134 or 2.44999999999999982e97 < d < 1.1999999999999999e133 or 1.4500000000000001e149 < d

    1. Initial program 23.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto c0 \cdot \frac{\color{blue}{0}}{2 \cdot w} \]

    if 5.3999999999999996e-134 < d < 2.44999999999999982e97 or 1.1999999999999999e133 < d < 1.4500000000000001e149

    1. Initial program 45.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. Simplified42.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)} \]
    3. Add Preprocessing
    4. Step-by-step derivation
      1. times-frac42.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-rr42.7%

      \[\leadsto \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 \color{blue}{\left(\frac{d}{D} \cdot \frac{d}{D}\right)}\right) - M \cdot M}\right) \]
    6. Step-by-step derivation
      1. times-frac42.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) \]
    7. Applied egg-rr43.1%

      \[\leadsto \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 \color{blue}{\left(\frac{d}{D} \cdot \frac{d}{D}\right)}\right) \cdot \left(\frac{c0}{w \cdot h} \cdot \left(\frac{d}{D} \cdot \frac{d}{D}\right)\right) - M \cdot M}\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification37.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq 5.4 \cdot 10^{-134} \lor \neg \left(d \leq 2.45 \cdot 10^{+97}\right) \land \left(d \leq 1.2 \cdot 10^{+133} \lor \neg \left(d \leq 1.45 \cdot 10^{+149}\right)\right):\\ \;\;\;\;c0 \cdot \frac{0}{2 \cdot w}\\ \mathbf{else}:\\ \;\;\;\;\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 \left(\frac{d}{D} \cdot \frac{d}{D}\right)\right) \cdot \left(\frac{c0}{w \cdot h} \cdot \left(\frac{d}{D} \cdot \frac{d}{D}\right)\right) - M \cdot M}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 33.8% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{c0}{2 \cdot w}\\ t_1 := \frac{c0}{w \cdot h}\\ t_2 := t\_1 \cdot \left(\frac{d}{D} \cdot \frac{d}{D}\right)\\ t_3 := t\_1 \cdot \frac{d \cdot d}{D \cdot D}\\ t_4 := c0 \cdot \frac{0}{2 \cdot w}\\ \mathbf{if}\;d \leq 4.4 \cdot 10^{-132}:\\ \;\;\;\;t\_4\\ \mathbf{elif}\;d \leq 2.6 \cdot 10^{+97}:\\ \;\;\;\;t\_0 \cdot \left(t\_3 + \sqrt{t\_3 \cdot t\_2 - M \cdot M}\right)\\ \mathbf{elif}\;d \leq 5.2 \cdot 10^{+133} \lor \neg \left(d \leq 1.38 \cdot 10^{+147}\right):\\ \;\;\;\;t\_4\\ \mathbf{else}:\\ \;\;\;\;t\_0 \cdot \left(t\_3 + \sqrt{t\_2 \cdot t\_2 - M \cdot M}\right)\\ \end{array} \end{array} \]
(FPCore (c0 w h D d M)
 :precision binary64
 (let* ((t_0 (/ c0 (* 2.0 w)))
        (t_1 (/ c0 (* w h)))
        (t_2 (* t_1 (* (/ d D) (/ d D))))
        (t_3 (* t_1 (/ (* d d) (* D D))))
        (t_4 (* c0 (/ 0.0 (* 2.0 w)))))
   (if (<= d 4.4e-132)
     t_4
     (if (<= d 2.6e+97)
       (* t_0 (+ t_3 (sqrt (- (* t_3 t_2) (* M M)))))
       (if (or (<= d 5.2e+133) (not (<= d 1.38e+147)))
         t_4
         (* t_0 (+ t_3 (sqrt (- (* t_2 t_2) (* M M))))))))))
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 / (w * h);
	double t_2 = t_1 * ((d / D) * (d / D));
	double t_3 = t_1 * ((d * d) / (D * D));
	double t_4 = c0 * (0.0 / (2.0 * w));
	double tmp;
	if (d <= 4.4e-132) {
		tmp = t_4;
	} else if (d <= 2.6e+97) {
		tmp = t_0 * (t_3 + sqrt(((t_3 * t_2) - (M * M))));
	} else if ((d <= 5.2e+133) || !(d <= 1.38e+147)) {
		tmp = t_4;
	} else {
		tmp = t_0 * (t_3 + sqrt(((t_2 * t_2) - (M * M))));
	}
	return tmp;
}
real(8) function code(c0, w, h, d, d_1, m)
    real(8), intent (in) :: c0
    real(8), intent (in) :: w
    real(8), intent (in) :: h
    real(8), intent (in) :: d
    real(8), intent (in) :: d_1
    real(8), intent (in) :: m
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: t_3
    real(8) :: t_4
    real(8) :: tmp
    t_0 = c0 / (2.0d0 * w)
    t_1 = c0 / (w * h)
    t_2 = t_1 * ((d_1 / d) * (d_1 / d))
    t_3 = t_1 * ((d_1 * d_1) / (d * d))
    t_4 = c0 * (0.0d0 / (2.0d0 * w))
    if (d_1 <= 4.4d-132) then
        tmp = t_4
    else if (d_1 <= 2.6d+97) then
        tmp = t_0 * (t_3 + sqrt(((t_3 * t_2) - (m * m))))
    else if ((d_1 <= 5.2d+133) .or. (.not. (d_1 <= 1.38d+147))) then
        tmp = t_4
    else
        tmp = t_0 * (t_3 + sqrt(((t_2 * t_2) - (m * m))))
    end if
    code = tmp
end function
public static double code(double c0, double w, double h, double D, double d, double M) {
	double t_0 = c0 / (2.0 * w);
	double t_1 = c0 / (w * h);
	double t_2 = t_1 * ((d / D) * (d / D));
	double t_3 = t_1 * ((d * d) / (D * D));
	double t_4 = c0 * (0.0 / (2.0 * w));
	double tmp;
	if (d <= 4.4e-132) {
		tmp = t_4;
	} else if (d <= 2.6e+97) {
		tmp = t_0 * (t_3 + Math.sqrt(((t_3 * t_2) - (M * M))));
	} else if ((d <= 5.2e+133) || !(d <= 1.38e+147)) {
		tmp = t_4;
	} else {
		tmp = t_0 * (t_3 + Math.sqrt(((t_2 * t_2) - (M * M))));
	}
	return tmp;
}
def code(c0, w, h, D, d, M):
	t_0 = c0 / (2.0 * w)
	t_1 = c0 / (w * h)
	t_2 = t_1 * ((d / D) * (d / D))
	t_3 = t_1 * ((d * d) / (D * D))
	t_4 = c0 * (0.0 / (2.0 * w))
	tmp = 0
	if d <= 4.4e-132:
		tmp = t_4
	elif d <= 2.6e+97:
		tmp = t_0 * (t_3 + math.sqrt(((t_3 * t_2) - (M * M))))
	elif (d <= 5.2e+133) or not (d <= 1.38e+147):
		tmp = t_4
	else:
		tmp = t_0 * (t_3 + math.sqrt(((t_2 * t_2) - (M * M))))
	return tmp
function code(c0, w, h, D, d, M)
	t_0 = Float64(c0 / Float64(2.0 * w))
	t_1 = Float64(c0 / Float64(w * h))
	t_2 = Float64(t_1 * Float64(Float64(d / D) * Float64(d / D)))
	t_3 = Float64(t_1 * Float64(Float64(d * d) / Float64(D * D)))
	t_4 = Float64(c0 * Float64(0.0 / Float64(2.0 * w)))
	tmp = 0.0
	if (d <= 4.4e-132)
		tmp = t_4;
	elseif (d <= 2.6e+97)
		tmp = Float64(t_0 * Float64(t_3 + sqrt(Float64(Float64(t_3 * t_2) - Float64(M * M)))));
	elseif ((d <= 5.2e+133) || !(d <= 1.38e+147))
		tmp = t_4;
	else
		tmp = Float64(t_0 * Float64(t_3 + sqrt(Float64(Float64(t_2 * t_2) - Float64(M * M)))));
	end
	return tmp
end
function tmp_2 = code(c0, w, h, D, d, M)
	t_0 = c0 / (2.0 * w);
	t_1 = c0 / (w * h);
	t_2 = t_1 * ((d / D) * (d / D));
	t_3 = t_1 * ((d * d) / (D * D));
	t_4 = c0 * (0.0 / (2.0 * w));
	tmp = 0.0;
	if (d <= 4.4e-132)
		tmp = t_4;
	elseif (d <= 2.6e+97)
		tmp = t_0 * (t_3 + sqrt(((t_3 * t_2) - (M * M))));
	elseif ((d <= 5.2e+133) || ~((d <= 1.38e+147)))
		tmp = t_4;
	else
		tmp = t_0 * (t_3 + sqrt(((t_2 * t_2) - (M * M))));
	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[(c0 / N[(w * h), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(t$95$1 * N[(N[(d / D), $MachinePrecision] * N[(d / D), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(t$95$1 * N[(N[(d * d), $MachinePrecision] / N[(D * D), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[(c0 * N[(0.0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, 4.4e-132], t$95$4, If[LessEqual[d, 2.6e+97], N[(t$95$0 * N[(t$95$3 + N[Sqrt[N[(N[(t$95$3 * t$95$2), $MachinePrecision] - N[(M * M), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[d, 5.2e+133], N[Not[LessEqual[d, 1.38e+147]], $MachinePrecision]], t$95$4, N[(t$95$0 * N[(t$95$3 + N[Sqrt[N[(N[(t$95$2 * t$95$2), $MachinePrecision] - N[(M * M), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{c0}{2 \cdot w}\\
t_1 := \frac{c0}{w \cdot h}\\
t_2 := t\_1 \cdot \left(\frac{d}{D} \cdot \frac{d}{D}\right)\\
t_3 := t\_1 \cdot \frac{d \cdot d}{D \cdot D}\\
t_4 := c0 \cdot \frac{0}{2 \cdot w}\\
\mathbf{if}\;d \leq 4.4 \cdot 10^{-132}:\\
\;\;\;\;t\_4\\

\mathbf{elif}\;d \leq 2.6 \cdot 10^{+97}:\\
\;\;\;\;t\_0 \cdot \left(t\_3 + \sqrt{t\_3 \cdot t\_2 - M \cdot M}\right)\\

\mathbf{elif}\;d \leq 5.2 \cdot 10^{+133} \lor \neg \left(d \leq 1.38 \cdot 10^{+147}\right):\\
\;\;\;\;t\_4\\

\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \left(t\_3 + \sqrt{t\_2 \cdot t\_2 - M \cdot M}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < 4.39999999999999981e-132 or 2.6e97 < d < 5.1999999999999995e133 or 1.37999999999999991e147 < d

    1. Initial program 23.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto c0 \cdot \frac{\color{blue}{0}}{2 \cdot w} \]

    if 4.39999999999999981e-132 < d < 2.6e97

    1. Initial program 43.1%

      \[\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \]
    2. Simplified40.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. times-frac40.5%

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

      \[\leadsto \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 \color{blue}{\left(\frac{d}{D} \cdot \frac{d}{D}\right)}\right) - M \cdot M}\right) \]

    if 5.1999999999999995e133 < d < 1.37999999999999991e147

    1. Initial program 60.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. Simplified60.0%

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

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

      \[\leadsto \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 \color{blue}{\left(\frac{d}{D} \cdot \frac{d}{D}\right)}\right) - M \cdot M}\right) \]
    6. Step-by-step derivation
      1. times-frac60.0%

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

      \[\leadsto \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 \color{blue}{\left(\frac{d}{D} \cdot \frac{d}{D}\right)}\right) \cdot \left(\frac{c0}{w \cdot h} \cdot \left(\frac{d}{D} \cdot \frac{d}{D}\right)\right) - M \cdot M}\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification37.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq 4.4 \cdot 10^{-132}:\\ \;\;\;\;c0 \cdot \frac{0}{2 \cdot w}\\ \mathbf{elif}\;d \leq 2.6 \cdot 10^{+97}:\\ \;\;\;\;\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 \left(\frac{d}{D} \cdot \frac{d}{D}\right)\right) - M \cdot M}\right)\\ \mathbf{elif}\;d \leq 5.2 \cdot 10^{+133} \lor \neg \left(d \leq 1.38 \cdot 10^{+147}\right):\\ \;\;\;\;c0 \cdot \frac{0}{2 \cdot w}\\ \mathbf{else}:\\ \;\;\;\;\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 \left(\frac{d}{D} \cdot \frac{d}{D}\right)\right) \cdot \left(\frac{c0}{w \cdot h} \cdot \left(\frac{d}{D} \cdot \frac{d}{D}\right)\right) - M \cdot M}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 33.9% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{c0}{2 \cdot w}\\ t_1 := \frac{c0}{w \cdot h}\\ t_2 := t\_1 \cdot \left(\frac{d}{D} \cdot \frac{d}{D}\right)\\ t_3 := t\_1 \cdot \frac{d \cdot d}{D \cdot D}\\ t_4 := c0 \cdot \frac{0}{2 \cdot w}\\ \mathbf{if}\;d \leq 4 \cdot 10^{-134}:\\ \;\;\;\;t\_4\\ \mathbf{elif}\;d \leq 2.1 \cdot 10^{+97}:\\ \;\;\;\;t\_0 \cdot \left(t\_3 + \sqrt{t\_3 \cdot t\_3 - M \cdot M}\right)\\ \mathbf{elif}\;d \leq 7.5 \cdot 10^{+133} \lor \neg \left(d \leq 3.6 \cdot 10^{+148}\right):\\ \;\;\;\;t\_4\\ \mathbf{else}:\\ \;\;\;\;t\_0 \cdot \left(t\_3 + \sqrt{t\_2 \cdot t\_2 - M \cdot M}\right)\\ \end{array} \end{array} \]
(FPCore (c0 w h D d M)
 :precision binary64
 (let* ((t_0 (/ c0 (* 2.0 w)))
        (t_1 (/ c0 (* w h)))
        (t_2 (* t_1 (* (/ d D) (/ d D))))
        (t_3 (* t_1 (/ (* d d) (* D D))))
        (t_4 (* c0 (/ 0.0 (* 2.0 w)))))
   (if (<= d 4e-134)
     t_4
     (if (<= d 2.1e+97)
       (* t_0 (+ t_3 (sqrt (- (* t_3 t_3) (* M M)))))
       (if (or (<= d 7.5e+133) (not (<= d 3.6e+148)))
         t_4
         (* t_0 (+ t_3 (sqrt (- (* t_2 t_2) (* M M))))))))))
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 / (w * h);
	double t_2 = t_1 * ((d / D) * (d / D));
	double t_3 = t_1 * ((d * d) / (D * D));
	double t_4 = c0 * (0.0 / (2.0 * w));
	double tmp;
	if (d <= 4e-134) {
		tmp = t_4;
	} else if (d <= 2.1e+97) {
		tmp = t_0 * (t_3 + sqrt(((t_3 * t_3) - (M * M))));
	} else if ((d <= 7.5e+133) || !(d <= 3.6e+148)) {
		tmp = t_4;
	} else {
		tmp = t_0 * (t_3 + sqrt(((t_2 * t_2) - (M * M))));
	}
	return tmp;
}
real(8) function code(c0, w, h, d, d_1, m)
    real(8), intent (in) :: c0
    real(8), intent (in) :: w
    real(8), intent (in) :: h
    real(8), intent (in) :: d
    real(8), intent (in) :: d_1
    real(8), intent (in) :: m
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: t_3
    real(8) :: t_4
    real(8) :: tmp
    t_0 = c0 / (2.0d0 * w)
    t_1 = c0 / (w * h)
    t_2 = t_1 * ((d_1 / d) * (d_1 / d))
    t_3 = t_1 * ((d_1 * d_1) / (d * d))
    t_4 = c0 * (0.0d0 / (2.0d0 * w))
    if (d_1 <= 4d-134) then
        tmp = t_4
    else if (d_1 <= 2.1d+97) then
        tmp = t_0 * (t_3 + sqrt(((t_3 * t_3) - (m * m))))
    else if ((d_1 <= 7.5d+133) .or. (.not. (d_1 <= 3.6d+148))) then
        tmp = t_4
    else
        tmp = t_0 * (t_3 + sqrt(((t_2 * t_2) - (m * m))))
    end if
    code = tmp
end function
public static double code(double c0, double w, double h, double D, double d, double M) {
	double t_0 = c0 / (2.0 * w);
	double t_1 = c0 / (w * h);
	double t_2 = t_1 * ((d / D) * (d / D));
	double t_3 = t_1 * ((d * d) / (D * D));
	double t_4 = c0 * (0.0 / (2.0 * w));
	double tmp;
	if (d <= 4e-134) {
		tmp = t_4;
	} else if (d <= 2.1e+97) {
		tmp = t_0 * (t_3 + Math.sqrt(((t_3 * t_3) - (M * M))));
	} else if ((d <= 7.5e+133) || !(d <= 3.6e+148)) {
		tmp = t_4;
	} else {
		tmp = t_0 * (t_3 + Math.sqrt(((t_2 * t_2) - (M * M))));
	}
	return tmp;
}
def code(c0, w, h, D, d, M):
	t_0 = c0 / (2.0 * w)
	t_1 = c0 / (w * h)
	t_2 = t_1 * ((d / D) * (d / D))
	t_3 = t_1 * ((d * d) / (D * D))
	t_4 = c0 * (0.0 / (2.0 * w))
	tmp = 0
	if d <= 4e-134:
		tmp = t_4
	elif d <= 2.1e+97:
		tmp = t_0 * (t_3 + math.sqrt(((t_3 * t_3) - (M * M))))
	elif (d <= 7.5e+133) or not (d <= 3.6e+148):
		tmp = t_4
	else:
		tmp = t_0 * (t_3 + math.sqrt(((t_2 * t_2) - (M * M))))
	return tmp
function code(c0, w, h, D, d, M)
	t_0 = Float64(c0 / Float64(2.0 * w))
	t_1 = Float64(c0 / Float64(w * h))
	t_2 = Float64(t_1 * Float64(Float64(d / D) * Float64(d / D)))
	t_3 = Float64(t_1 * Float64(Float64(d * d) / Float64(D * D)))
	t_4 = Float64(c0 * Float64(0.0 / Float64(2.0 * w)))
	tmp = 0.0
	if (d <= 4e-134)
		tmp = t_4;
	elseif (d <= 2.1e+97)
		tmp = Float64(t_0 * Float64(t_3 + sqrt(Float64(Float64(t_3 * t_3) - Float64(M * M)))));
	elseif ((d <= 7.5e+133) || !(d <= 3.6e+148))
		tmp = t_4;
	else
		tmp = Float64(t_0 * Float64(t_3 + sqrt(Float64(Float64(t_2 * t_2) - Float64(M * M)))));
	end
	return tmp
end
function tmp_2 = code(c0, w, h, D, d, M)
	t_0 = c0 / (2.0 * w);
	t_1 = c0 / (w * h);
	t_2 = t_1 * ((d / D) * (d / D));
	t_3 = t_1 * ((d * d) / (D * D));
	t_4 = c0 * (0.0 / (2.0 * w));
	tmp = 0.0;
	if (d <= 4e-134)
		tmp = t_4;
	elseif (d <= 2.1e+97)
		tmp = t_0 * (t_3 + sqrt(((t_3 * t_3) - (M * M))));
	elseif ((d <= 7.5e+133) || ~((d <= 3.6e+148)))
		tmp = t_4;
	else
		tmp = t_0 * (t_3 + sqrt(((t_2 * t_2) - (M * M))));
	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[(c0 / N[(w * h), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(t$95$1 * N[(N[(d / D), $MachinePrecision] * N[(d / D), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(t$95$1 * N[(N[(d * d), $MachinePrecision] / N[(D * D), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[(c0 * N[(0.0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, 4e-134], t$95$4, If[LessEqual[d, 2.1e+97], N[(t$95$0 * N[(t$95$3 + N[Sqrt[N[(N[(t$95$3 * t$95$3), $MachinePrecision] - N[(M * M), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[d, 7.5e+133], N[Not[LessEqual[d, 3.6e+148]], $MachinePrecision]], t$95$4, N[(t$95$0 * N[(t$95$3 + N[Sqrt[N[(N[(t$95$2 * t$95$2), $MachinePrecision] - N[(M * M), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{c0}{2 \cdot w}\\
t_1 := \frac{c0}{w \cdot h}\\
t_2 := t\_1 \cdot \left(\frac{d}{D} \cdot \frac{d}{D}\right)\\
t_3 := t\_1 \cdot \frac{d \cdot d}{D \cdot D}\\
t_4 := c0 \cdot \frac{0}{2 \cdot w}\\
\mathbf{if}\;d \leq 4 \cdot 10^{-134}:\\
\;\;\;\;t\_4\\

\mathbf{elif}\;d \leq 2.1 \cdot 10^{+97}:\\
\;\;\;\;t\_0 \cdot \left(t\_3 + \sqrt{t\_3 \cdot t\_3 - M \cdot M}\right)\\

\mathbf{elif}\;d \leq 7.5 \cdot 10^{+133} \lor \neg \left(d \leq 3.6 \cdot 10^{+148}\right):\\
\;\;\;\;t\_4\\

\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \left(t\_3 + \sqrt{t\_2 \cdot t\_2 - M \cdot M}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < 4.00000000000000016e-134 or 2.10000000000000012e97 < d < 7.49999999999999992e133 or 3.60000000000000006e148 < d

    1. Initial program 23.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto c0 \cdot \frac{\color{blue}{0}}{2 \cdot w} \]

    if 4.00000000000000016e-134 < d < 2.10000000000000012e97

    1. Initial program 43.1%

      \[\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \]
    2. Simplified40.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

    if 7.49999999999999992e133 < d < 3.60000000000000006e148

    1. Initial program 60.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. Simplified60.0%

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

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

      \[\leadsto \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 \color{blue}{\left(\frac{d}{D} \cdot \frac{d}{D}\right)}\right) - M \cdot M}\right) \]
    6. Step-by-step derivation
      1. times-frac60.0%

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

      \[\leadsto \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 \color{blue}{\left(\frac{d}{D} \cdot \frac{d}{D}\right)}\right) \cdot \left(\frac{c0}{w \cdot h} \cdot \left(\frac{d}{D} \cdot \frac{d}{D}\right)\right) - M \cdot M}\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification37.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq 4 \cdot 10^{-134}:\\ \;\;\;\;c0 \cdot \frac{0}{2 \cdot w}\\ \mathbf{elif}\;d \leq 2.1 \cdot 10^{+97}:\\ \;\;\;\;\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)\\ \mathbf{elif}\;d \leq 7.5 \cdot 10^{+133} \lor \neg \left(d \leq 3.6 \cdot 10^{+148}\right):\\ \;\;\;\;c0 \cdot \frac{0}{2 \cdot w}\\ \mathbf{else}:\\ \;\;\;\;\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 \left(\frac{d}{D} \cdot \frac{d}{D}\right)\right) \cdot \left(\frac{c0}{w \cdot h} \cdot \left(\frac{d}{D} \cdot \frac{d}{D}\right)\right) - M \cdot M}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 33.9% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{c0}{w \cdot h}\\ t_1 := t\_0 \cdot \frac{d \cdot d}{D \cdot D}\\ \mathbf{if}\;d \leq 1.2 \cdot 10^{-133} \lor \neg \left(d \leq 3.6 \cdot 10^{+97}\right):\\ \;\;\;\;c0 \cdot \frac{0}{2 \cdot w}\\ \mathbf{else}:\\ \;\;\;\;\frac{c0}{2 \cdot w} \cdot \left(\sqrt{t\_1 \cdot t\_1 - M \cdot M} + t\_0 \cdot \left(\frac{d}{D} \cdot \frac{d}{D}\right)\right)\\ \end{array} \end{array} \]
(FPCore (c0 w h D d M)
 :precision binary64
 (let* ((t_0 (/ c0 (* w h))) (t_1 (* t_0 (/ (* d d) (* D D)))))
   (if (or (<= d 1.2e-133) (not (<= d 3.6e+97)))
     (* c0 (/ 0.0 (* 2.0 w)))
     (*
      (/ c0 (* 2.0 w))
      (+ (sqrt (- (* t_1 t_1) (* M M))) (* t_0 (* (/ d D) (/ d D))))))))
double code(double c0, double w, double h, double D, double d, double M) {
	double t_0 = c0 / (w * h);
	double t_1 = t_0 * ((d * d) / (D * D));
	double tmp;
	if ((d <= 1.2e-133) || !(d <= 3.6e+97)) {
		tmp = c0 * (0.0 / (2.0 * w));
	} else {
		tmp = (c0 / (2.0 * w)) * (sqrt(((t_1 * t_1) - (M * M))) + (t_0 * ((d / D) * (d / D))));
	}
	return tmp;
}
real(8) function code(c0, w, h, d, d_1, m)
    real(8), intent (in) :: c0
    real(8), intent (in) :: w
    real(8), intent (in) :: h
    real(8), intent (in) :: d
    real(8), intent (in) :: d_1
    real(8), intent (in) :: m
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = c0 / (w * h)
    t_1 = t_0 * ((d_1 * d_1) / (d * d))
    if ((d_1 <= 1.2d-133) .or. (.not. (d_1 <= 3.6d+97))) then
        tmp = c0 * (0.0d0 / (2.0d0 * w))
    else
        tmp = (c0 / (2.0d0 * w)) * (sqrt(((t_1 * t_1) - (m * m))) + (t_0 * ((d_1 / d) * (d_1 / d))))
    end if
    code = tmp
end function
public static double code(double c0, double w, double h, double D, double d, double M) {
	double t_0 = c0 / (w * h);
	double t_1 = t_0 * ((d * d) / (D * D));
	double tmp;
	if ((d <= 1.2e-133) || !(d <= 3.6e+97)) {
		tmp = c0 * (0.0 / (2.0 * w));
	} else {
		tmp = (c0 / (2.0 * w)) * (Math.sqrt(((t_1 * t_1) - (M * M))) + (t_0 * ((d / D) * (d / D))));
	}
	return tmp;
}
def code(c0, w, h, D, d, M):
	t_0 = c0 / (w * h)
	t_1 = t_0 * ((d * d) / (D * D))
	tmp = 0
	if (d <= 1.2e-133) or not (d <= 3.6e+97):
		tmp = c0 * (0.0 / (2.0 * w))
	else:
		tmp = (c0 / (2.0 * w)) * (math.sqrt(((t_1 * t_1) - (M * M))) + (t_0 * ((d / D) * (d / D))))
	return tmp
function code(c0, w, h, D, d, M)
	t_0 = Float64(c0 / Float64(w * h))
	t_1 = Float64(t_0 * Float64(Float64(d * d) / Float64(D * D)))
	tmp = 0.0
	if ((d <= 1.2e-133) || !(d <= 3.6e+97))
		tmp = Float64(c0 * Float64(0.0 / Float64(2.0 * w)));
	else
		tmp = Float64(Float64(c0 / Float64(2.0 * w)) * Float64(sqrt(Float64(Float64(t_1 * t_1) - Float64(M * M))) + Float64(t_0 * Float64(Float64(d / D) * Float64(d / D)))));
	end
	return tmp
end
function tmp_2 = code(c0, w, h, D, d, M)
	t_0 = c0 / (w * h);
	t_1 = t_0 * ((d * d) / (D * D));
	tmp = 0.0;
	if ((d <= 1.2e-133) || ~((d <= 3.6e+97)))
		tmp = c0 * (0.0 / (2.0 * w));
	else
		tmp = (c0 / (2.0 * w)) * (sqrt(((t_1 * t_1) - (M * M))) + (t_0 * ((d / D) * (d / D))));
	end
	tmp_2 = tmp;
end
code[c0_, w_, h_, D_, d_, M_] := Block[{t$95$0 = N[(c0 / N[(w * h), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 * N[(N[(d * d), $MachinePrecision] / N[(D * D), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[d, 1.2e-133], N[Not[LessEqual[d, 3.6e+97]], $MachinePrecision]], N[(c0 * N[(0.0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision] * N[(N[Sqrt[N[(N[(t$95$1 * t$95$1), $MachinePrecision] - N[(M * M), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + N[(t$95$0 * N[(N[(d / D), $MachinePrecision] * N[(d / D), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{c0}{w \cdot h}\\
t_1 := t\_0 \cdot \frac{d \cdot d}{D \cdot D}\\
\mathbf{if}\;d \leq 1.2 \cdot 10^{-133} \lor \neg \left(d \leq 3.6 \cdot 10^{+97}\right):\\
\;\;\;\;c0 \cdot \frac{0}{2 \cdot w}\\

\mathbf{else}:\\
\;\;\;\;\frac{c0}{2 \cdot w} \cdot \left(\sqrt{t\_1 \cdot t\_1 - M \cdot M} + t\_0 \cdot \left(\frac{d}{D} \cdot \frac{d}{D}\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < 1.2e-133 or 3.59999999999999966e97 < d

    1. Initial program 24.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. Simplified40.7%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto c0 \cdot \frac{\color{blue}{0}}{2 \cdot w} \]

    if 1.2e-133 < d < 3.59999999999999966e97

    1. Initial program 43.1%

      \[\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \]
    2. Simplified40.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. times-frac40.5%

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

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(\frac{c0}{w \cdot h} \cdot \color{blue}{\left(\frac{d}{D} \cdot \frac{d}{D}\right)} + \sqrt{\left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\right) \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\right) - M \cdot M}\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification36.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq 1.2 \cdot 10^{-133} \lor \neg \left(d \leq 3.6 \cdot 10^{+97}\right):\\ \;\;\;\;c0 \cdot \frac{0}{2 \cdot w}\\ \mathbf{else}:\\ \;\;\;\;\frac{c0}{2 \cdot w} \cdot \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 \left(\frac{d}{D} \cdot \frac{d}{D}\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 34.1% accurate, 21.6× speedup?

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

\\
c0 \cdot \frac{0}{2 \cdot w}
\end{array}
Derivation
  1. Initial program 26.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. Simplified40.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 4.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

Reproduce

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