Henrywood and Agarwal, Equation (13)

Percentage Accurate: 24.1% → 61.6%
Time: 32.0s
Alternatives: 6
Speedup: 151.0×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 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.1% accurate, 1.0× speedup?

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

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

Alternative 1: 61.6% accurate, 0.4× 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(2 \cdot \frac{c0 \cdot {d}^{2}}{\left(w \cdot h\right) \cdot {D}^{2}}\right)\\ \mathbf{else}:\\ \;\;\;\;0.25 \cdot \frac{h \cdot {M}^{2}}{{\left(\frac{d}{D}\right)}^{2}}\\ \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 (* 2.0 (/ (* c0 (pow d 2.0)) (* (* w h) (pow D 2.0)))))
     (* 0.25 (/ (* h (pow M 2.0)) (pow (/ d D) 2.0))))))
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 * (2.0 * ((c0 * pow(d, 2.0)) / ((w * h) * pow(D, 2.0))));
	} else {
		tmp = 0.25 * ((h * pow(M, 2.0)) / pow((d / D), 2.0));
	}
	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 * (2.0 * ((c0 * Math.pow(d, 2.0)) / ((w * h) * Math.pow(D, 2.0))));
	} else {
		tmp = 0.25 * ((h * Math.pow(M, 2.0)) / Math.pow((d / D), 2.0));
	}
	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 * (2.0 * ((c0 * math.pow(d, 2.0)) / ((w * h) * math.pow(D, 2.0))))
	else:
		tmp = 0.25 * ((h * math.pow(M, 2.0)) / math.pow((d / D), 2.0))
	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(2.0 * Float64(Float64(c0 * (d ^ 2.0)) / Float64(Float64(w * h) * (D ^ 2.0)))));
	else
		tmp = Float64(0.25 * Float64(Float64(h * (M ^ 2.0)) / (Float64(d / D) ^ 2.0)));
	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 * (2.0 * ((c0 * (d ^ 2.0)) / ((w * h) * (D ^ 2.0))));
	else
		tmp = 0.25 * ((h * (M ^ 2.0)) / ((d / D) ^ 2.0));
	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[(2.0 * N[(N[(c0 * N[Power[d, 2.0], $MachinePrecision]), $MachinePrecision] / N[(N[(w * h), $MachinePrecision] * N[Power[D, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.25 * N[(N[(h * N[Power[M, 2.0], $MachinePrecision]), $MachinePrecision] / N[Power[N[(d / D), $MachinePrecision], 2.0], $MachinePrecision]), $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(2 \cdot \frac{c0 \cdot {d}^{2}}{\left(w \cdot h\right) \cdot {D}^{2}}\right)\\

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


\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 75.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. Step-by-step derivation
      1. +-commutative75.9%

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

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

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

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D} + \sqrt{\color{blue}{\mathsf{fma}\left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}, \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}, -M \cdot M\right)}}\right) \]
    3. Simplified70.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)} \]
    4. Add Preprocessing
    5. Taylor expanded in c0 around inf 77.1%

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

    if +inf.0 < (*.f64 (/.f64 c0 (*.f64 2 w)) (+.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (sqrt.f64 (-.f64 (*.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D)))) (*.f64 M M)))))

    1. Initial program 0.0%

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

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

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{\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)} \]
      3. times-frac0.6%

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

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D} + \sqrt{\color{blue}{\mathsf{fma}\left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}, \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}, -M \cdot M\right)}}\right) \]
    3. Simplified3.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)} \]
    4. Add Preprocessing
    5. Taylor expanded in c0 around -inf 3.7%

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

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

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \mathsf{fma}\left(0.5, \frac{{D}^{2}}{c0} \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\left(h \cdot w\right) \cdot {M}^{2}}{{d}^{2}}\right)\right)}, 0\right) \]
      2. expm1-udef22.9%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \mathsf{fma}\left(0.5, \frac{{D}^{2}}{c0} \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(\frac{\left(h \cdot w\right) \cdot {M}^{2}}{{d}^{2}}\right)} - 1\right)}, 0\right) \]
      3. div-inv22.9%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \mathsf{fma}\left(0.5, \frac{{D}^{2}}{c0} \cdot \left(e^{\mathsf{log1p}\left(\color{blue}{\left(\left(h \cdot w\right) \cdot {M}^{2}\right) \cdot \frac{1}{{d}^{2}}}\right)} - 1\right), 0\right) \]
      4. pow-flip22.9%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \mathsf{fma}\left(0.5, \frac{{D}^{2}}{c0} \cdot \left(e^{\mathsf{log1p}\left(\left(\left(h \cdot w\right) \cdot {M}^{2}\right) \cdot \color{blue}{{d}^{\left(-2\right)}}\right)} - 1\right), 0\right) \]
      5. metadata-eval22.9%

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

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

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \mathsf{fma}\left(0.5, \frac{{D}^{2}}{c0} \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\left(\left(h \cdot w\right) \cdot {M}^{2}\right) \cdot {d}^{-2}\right)\right)}, 0\right) \]
      2. expm1-log1p25.9%

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

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

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

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

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

        \[\leadsto 0.25 \cdot \frac{\color{blue}{\left({M}^{2} \cdot h\right) \cdot {D}^{2}}}{{d}^{2}} \]
      2. associate-/l*41.7%

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

        \[\leadsto 0.25 \cdot \frac{\color{blue}{h \cdot {M}^{2}}}{\frac{{d}^{2}}{{D}^{2}}} \]
      4. unpow241.7%

        \[\leadsto 0.25 \cdot \frac{h \cdot {M}^{2}}{\frac{\color{blue}{d \cdot d}}{{D}^{2}}} \]
      5. unpow241.7%

        \[\leadsto 0.25 \cdot \frac{h \cdot {M}^{2}}{\frac{d \cdot d}{\color{blue}{D \cdot D}}} \]
      6. times-frac53.3%

        \[\leadsto 0.25 \cdot \frac{h \cdot {M}^{2}}{\color{blue}{\frac{d}{D} \cdot \frac{d}{D}}} \]
      7. unpow253.3%

        \[\leadsto 0.25 \cdot \frac{h \cdot {M}^{2}}{\color{blue}{{\left(\frac{d}{D}\right)}^{2}}} \]
    13. Simplified53.3%

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

Alternative 2: 61.8% accurate, 0.4× speedup?

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


\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 75.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. Step-by-step derivation
      1. +-commutative0.0%

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

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{\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)} \]
      3. times-frac0.6%

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

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D} + \sqrt{\color{blue}{\mathsf{fma}\left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}, \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}, -M \cdot M\right)}}\right) \]
    3. Simplified3.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)} \]
    4. Add Preprocessing
    5. Taylor expanded in c0 around -inf 3.7%

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

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

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \mathsf{fma}\left(0.5, \frac{{D}^{2}}{c0} \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\left(h \cdot w\right) \cdot {M}^{2}}{{d}^{2}}\right)\right)}, 0\right) \]
      2. expm1-udef22.9%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \mathsf{fma}\left(0.5, \frac{{D}^{2}}{c0} \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(\frac{\left(h \cdot w\right) \cdot {M}^{2}}{{d}^{2}}\right)} - 1\right)}, 0\right) \]
      3. div-inv22.9%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \mathsf{fma}\left(0.5, \frac{{D}^{2}}{c0} \cdot \left(e^{\mathsf{log1p}\left(\color{blue}{\left(\left(h \cdot w\right) \cdot {M}^{2}\right) \cdot \frac{1}{{d}^{2}}}\right)} - 1\right), 0\right) \]
      4. pow-flip22.9%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \mathsf{fma}\left(0.5, \frac{{D}^{2}}{c0} \cdot \left(e^{\mathsf{log1p}\left(\left(\left(h \cdot w\right) \cdot {M}^{2}\right) \cdot \color{blue}{{d}^{\left(-2\right)}}\right)} - 1\right), 0\right) \]
      5. metadata-eval22.9%

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

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

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \mathsf{fma}\left(0.5, \frac{{D}^{2}}{c0} \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\left(\left(h \cdot w\right) \cdot {M}^{2}\right) \cdot {d}^{-2}\right)\right)}, 0\right) \]
      2. expm1-log1p25.9%

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

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

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

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

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

        \[\leadsto 0.25 \cdot \frac{\color{blue}{\left({M}^{2} \cdot h\right) \cdot {D}^{2}}}{{d}^{2}} \]
      2. associate-/l*41.7%

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

        \[\leadsto 0.25 \cdot \frac{\color{blue}{h \cdot {M}^{2}}}{\frac{{d}^{2}}{{D}^{2}}} \]
      4. unpow241.7%

        \[\leadsto 0.25 \cdot \frac{h \cdot {M}^{2}}{\frac{\color{blue}{d \cdot d}}{{D}^{2}}} \]
      5. unpow241.7%

        \[\leadsto 0.25 \cdot \frac{h \cdot {M}^{2}}{\frac{d \cdot d}{\color{blue}{D \cdot D}}} \]
      6. times-frac53.3%

        \[\leadsto 0.25 \cdot \frac{h \cdot {M}^{2}}{\color{blue}{\frac{d}{D} \cdot \frac{d}{D}}} \]
      7. unpow253.3%

        \[\leadsto 0.25 \cdot \frac{h \cdot {M}^{2}}{\color{blue}{{\left(\frac{d}{D}\right)}^{2}}} \]
    13. Simplified53.3%

      \[\leadsto \color{blue}{0.25 \cdot \frac{h \cdot {M}^{2}}{{\left(\frac{d}{D}\right)}^{2}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification61.1%

    \[\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}:\\ \;\;\;\;0.25 \cdot \frac{h \cdot {M}^{2}}{{\left(\frac{d}{D}\right)}^{2}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 54.9% accurate, 0.5× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;0\\


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

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

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{\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)} \]
      3. times-frac0.6%

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

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D} + \sqrt{\color{blue}{\mathsf{fma}\left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}, \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}, -M \cdot M\right)}}\right) \]
    3. Simplified3.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)} \]
    4. Add Preprocessing
    5. Taylor expanded in c0 around -inf 3.7%

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

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{\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. distribute-lft-in2.5%

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

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{0} \]
    8. Taylor expanded in c0 around 0 44.2%

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

    \[\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}:\\ \;\;\;\;0\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 45.1% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
t_0 := \frac{d}{\frac{D}{c0}}\\
\mathbf{if}\;w \leq -2.3 \cdot 10^{+134}:\\
\;\;\;\;0\\

\mathbf{elif}\;w \leq -5.4 \cdot 10^{-43} \lor \neg \left(w \leq -7.6 \cdot 10^{-125}\right) \land w \leq 1.6 \cdot 10^{+112}:\\
\;\;\;\;\frac{t_0 \cdot t_0}{h \cdot {w}^{2}}\\

\mathbf{else}:\\
\;\;\;\;0\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if w < -2.2999999999999998e134 or -5.39999999999999982e-43 < w < -7.6000000000000002e-125 or 1.59999999999999993e112 < w

    1. Initial program 12.4%

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

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

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{\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)} \]
      3. times-frac12.4%

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

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

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

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

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{\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. distribute-lft-in7.8%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(-\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)}\right) \]
    7. Simplified44.9%

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{0} \]
    8. Taylor expanded in c0 around 0 49.5%

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

    if -2.2999999999999998e134 < w < -5.39999999999999982e-43 or -7.6000000000000002e-125 < w < 1.59999999999999993e112

    1. Initial program 30.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. Simplified44.9%

      \[\leadsto \color{blue}{\frac{\frac{c0}{w}}{2} \cdot \mathsf{fma}\left(\frac{\frac{c0}{w}}{h}, \frac{d}{D} \cdot \frac{d}{D}, \sqrt{\mathsf{fma}\left(\frac{\frac{c0}{w}}{h}, \frac{d}{D} \cdot \frac{d}{D}, M\right) \cdot \left(\left(\frac{d}{D} \cdot \frac{d}{D}\right) \cdot \frac{\frac{c0}{w}}{h} - M\right)}\right)} \]
    3. Add Preprocessing
    4. Step-by-step derivation
      1. fma-udef46.9%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{{d}^{2}}{{D}^{2}} \cdot \frac{{c0}^{2}}{h \cdot {w}^{2}}} \]
      3. unpow231.4%

        \[\leadsto \frac{\color{blue}{d \cdot d}}{{D}^{2}} \cdot \frac{{c0}^{2}}{h \cdot {w}^{2}} \]
      4. unpow231.4%

        \[\leadsto \frac{d \cdot d}{\color{blue}{D \cdot D}} \cdot \frac{{c0}^{2}}{h \cdot {w}^{2}} \]
      5. times-frac39.0%

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

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

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

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

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

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\frac{{\left(\frac{d}{D}\right)}^{2} \cdot {c0}^{2}}{h \cdot {w}^{2}}}\right)} - 1 \]
      4. pow-prod-down20.3%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{{\left(\frac{d}{D} \cdot c0\right)}^{2}}}{h \cdot {w}^{2}}\right)} - 1 \]
    10. Applied egg-rr20.3%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{{\left(\frac{d}{D} \cdot c0\right)}^{2}}{h \cdot {w}^{2}}\right)} - 1} \]
    11. Step-by-step derivation
      1. expm1-def20.8%

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

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

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

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

        \[\leadsto \frac{\color{blue}{\frac{d \cdot c0}{D} \cdot \frac{d \cdot c0}{D}}}{h \cdot {w}^{2}} \]
      2. associate-/l*51.1%

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

        \[\leadsto \frac{\frac{d}{\frac{D}{c0}} \cdot \color{blue}{\frac{d}{\frac{D}{c0}}}}{h \cdot {w}^{2}} \]
    14. Applied egg-rr50.6%

      \[\leadsto \frac{\color{blue}{\frac{d}{\frac{D}{c0}} \cdot \frac{d}{\frac{D}{c0}}}}{h \cdot {w}^{2}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification50.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;w \leq -2.3 \cdot 10^{+134}:\\ \;\;\;\;0\\ \mathbf{elif}\;w \leq -5.4 \cdot 10^{-43} \lor \neg \left(w \leq -7.6 \cdot 10^{-125}\right) \land w \leq 1.6 \cdot 10^{+112}:\\ \;\;\;\;\frac{\frac{d}{\frac{D}{c0}} \cdot \frac{d}{\frac{D}{c0}}}{h \cdot {w}^{2}}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 41.1% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{d}{\frac{D}{c0}}\\ \mathbf{if}\;d \cdot d \leq 2 \cdot 10^{+163}:\\ \;\;\;\;\frac{t_0 \cdot t_0}{h \cdot {w}^{2}}\\ \mathbf{elif}\;d \cdot d \leq 5 \cdot 10^{+241}:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;\frac{c0}{2 \cdot w} \cdot \left(2 \cdot \left({\left(\frac{d}{D}\right)}^{2} \cdot \frac{\frac{c0}{h}}{w}\right)\right)\\ \end{array} \end{array} \]
(FPCore (c0 w h D d M)
 :precision binary64
 (let* ((t_0 (/ d (/ D c0))))
   (if (<= (* d d) 2e+163)
     (/ (* t_0 t_0) (* h (pow w 2.0)))
     (if (<= (* d d) 5e+241)
       0.0
       (* (/ c0 (* 2.0 w)) (* 2.0 (* (pow (/ d D) 2.0) (/ (/ c0 h) w))))))))
double code(double c0, double w, double h, double D, double d, double M) {
	double t_0 = d / (D / c0);
	double tmp;
	if ((d * d) <= 2e+163) {
		tmp = (t_0 * t_0) / (h * pow(w, 2.0));
	} else if ((d * d) <= 5e+241) {
		tmp = 0.0;
	} else {
		tmp = (c0 / (2.0 * w)) * (2.0 * (pow((d / D), 2.0) * ((c0 / h) / 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) :: t_0
    real(8) :: tmp
    t_0 = d_1 / (d / c0)
    if ((d_1 * d_1) <= 2d+163) then
        tmp = (t_0 * t_0) / (h * (w ** 2.0d0))
    else if ((d_1 * d_1) <= 5d+241) then
        tmp = 0.0d0
    else
        tmp = (c0 / (2.0d0 * w)) * (2.0d0 * (((d_1 / d) ** 2.0d0) * ((c0 / h) / w)))
    end if
    code = tmp
end function
public static double code(double c0, double w, double h, double D, double d, double M) {
	double t_0 = d / (D / c0);
	double tmp;
	if ((d * d) <= 2e+163) {
		tmp = (t_0 * t_0) / (h * Math.pow(w, 2.0));
	} else if ((d * d) <= 5e+241) {
		tmp = 0.0;
	} else {
		tmp = (c0 / (2.0 * w)) * (2.0 * (Math.pow((d / D), 2.0) * ((c0 / h) / w)));
	}
	return tmp;
}
def code(c0, w, h, D, d, M):
	t_0 = d / (D / c0)
	tmp = 0
	if (d * d) <= 2e+163:
		tmp = (t_0 * t_0) / (h * math.pow(w, 2.0))
	elif (d * d) <= 5e+241:
		tmp = 0.0
	else:
		tmp = (c0 / (2.0 * w)) * (2.0 * (math.pow((d / D), 2.0) * ((c0 / h) / w)))
	return tmp
function code(c0, w, h, D, d, M)
	t_0 = Float64(d / Float64(D / c0))
	tmp = 0.0
	if (Float64(d * d) <= 2e+163)
		tmp = Float64(Float64(t_0 * t_0) / Float64(h * (w ^ 2.0)));
	elseif (Float64(d * d) <= 5e+241)
		tmp = 0.0;
	else
		tmp = Float64(Float64(c0 / Float64(2.0 * w)) * Float64(2.0 * Float64((Float64(d / D) ^ 2.0) * Float64(Float64(c0 / h) / w))));
	end
	return tmp
end
function tmp_2 = code(c0, w, h, D, d, M)
	t_0 = d / (D / c0);
	tmp = 0.0;
	if ((d * d) <= 2e+163)
		tmp = (t_0 * t_0) / (h * (w ^ 2.0));
	elseif ((d * d) <= 5e+241)
		tmp = 0.0;
	else
		tmp = (c0 / (2.0 * w)) * (2.0 * (((d / D) ^ 2.0) * ((c0 / h) / w)));
	end
	tmp_2 = tmp;
end
code[c0_, w_, h_, D_, d_, M_] := Block[{t$95$0 = N[(d / N[(D / c0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(d * d), $MachinePrecision], 2e+163], N[(N[(t$95$0 * t$95$0), $MachinePrecision] / N[(h * N[Power[w, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(d * d), $MachinePrecision], 5e+241], 0.0, N[(N[(c0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision] * N[(2.0 * N[(N[Power[N[(d / D), $MachinePrecision], 2.0], $MachinePrecision] * N[(N[(c0 / h), $MachinePrecision] / w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{d}{\frac{D}{c0}}\\
\mathbf{if}\;d \cdot d \leq 2 \cdot 10^{+163}:\\
\;\;\;\;\frac{t_0 \cdot t_0}{h \cdot {w}^{2}}\\

\mathbf{elif}\;d \cdot d \leq 5 \cdot 10^{+241}:\\
\;\;\;\;0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 d d) < 1.9999999999999999e163

    1. Initial program 24.7%

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

      \[\leadsto \color{blue}{\frac{\frac{c0}{w}}{2} \cdot \mathsf{fma}\left(\frac{\frac{c0}{w}}{h}, \frac{d}{D} \cdot \frac{d}{D}, \sqrt{\mathsf{fma}\left(\frac{\frac{c0}{w}}{h}, \frac{d}{D} \cdot \frac{d}{D}, M\right) \cdot \left(\left(\frac{d}{D} \cdot \frac{d}{D}\right) \cdot \frac{\frac{c0}{w}}{h} - M\right)}\right)} \]
    3. Add Preprocessing
    4. Step-by-step derivation
      1. fma-udef43.6%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{{d}^{2}}{{D}^{2}} \cdot \frac{{c0}^{2}}{h \cdot {w}^{2}}} \]
      3. unpow227.0%

        \[\leadsto \frac{\color{blue}{d \cdot d}}{{D}^{2}} \cdot \frac{{c0}^{2}}{h \cdot {w}^{2}} \]
      4. unpow227.0%

        \[\leadsto \frac{d \cdot d}{\color{blue}{D \cdot D}} \cdot \frac{{c0}^{2}}{h \cdot {w}^{2}} \]
      5. times-frac36.9%

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

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

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

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

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

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\frac{{\left(\frac{d}{D}\right)}^{2} \cdot {c0}^{2}}{h \cdot {w}^{2}}}\right)} - 1 \]
      4. pow-prod-down21.3%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{{\left(\frac{d}{D} \cdot c0\right)}^{2}}}{h \cdot {w}^{2}}\right)} - 1 \]
    10. Applied egg-rr21.3%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{{\left(\frac{d}{D} \cdot c0\right)}^{2}}{h \cdot {w}^{2}}\right)} - 1} \]
    11. Step-by-step derivation
      1. expm1-def21.3%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{{\left(\frac{d}{D} \cdot c0\right)}^{2}}{h \cdot {w}^{2}}\right)\right)} \]
      2. expm1-log1p46.0%

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

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

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

        \[\leadsto \frac{\color{blue}{\frac{d \cdot c0}{D} \cdot \frac{d \cdot c0}{D}}}{h \cdot {w}^{2}} \]
      2. associate-/l*48.4%

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

        \[\leadsto \frac{\frac{d}{\frac{D}{c0}} \cdot \color{blue}{\frac{d}{\frac{D}{c0}}}}{h \cdot {w}^{2}} \]
    14. Applied egg-rr47.6%

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

    if 1.9999999999999999e163 < (*.f64 d d) < 5.00000000000000025e241

    1. Initial program 21.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. Step-by-step derivation
      1. +-commutative21.1%

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

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{\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)} \]
      3. times-frac13.0%

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

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D} + \sqrt{\color{blue}{\mathsf{fma}\left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}, \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}, -M \cdot M\right)}}\right) \]
    3. Simplified17.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)} \]
    4. Add Preprocessing
    5. Taylor expanded in c0 around -inf 25.3%

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

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{\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. distribute-lft-in16.8%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(-\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)}\right) \]
    7. Simplified44.9%

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{0} \]
    8. Taylor expanded in c0 around 0 53.3%

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

    if 5.00000000000000025e241 < (*.f64 d d)

    1. Initial program 28.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
    3. Step-by-step derivation
      1. frac-times28.6%

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

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

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

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

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

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

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(\color{blue}{\frac{d}{D} \cdot \left(\frac{d}{D} \cdot \frac{c0}{w \cdot h}\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) \]
    5. Taylor expanded in d around inf 35.5%

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

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

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

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

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

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

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

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

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

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

Alternative 6: 34.5% accurate, 151.0× speedup?

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

\\
0
\end{array}
Derivation
  1. Initial program 26.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. Step-by-step derivation
    1. +-commutative26.1%

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

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{\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)} \]
    3. times-frac25.0%

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

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D} + \sqrt{\color{blue}{\mathsf{fma}\left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}, \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}, -M \cdot M\right)}}\right) \]
  3. Simplified26.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)} \]
  4. Add Preprocessing
  5. Taylor expanded in c0 around -inf 4.6%

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

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{\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. distribute-lft-in3.8%

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

    \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{0} \]
  8. Taylor expanded in c0 around 0 31.7%

    \[\leadsto \color{blue}{0} \]
  9. Final simplification31.7%

    \[\leadsto 0 \]
  10. Add Preprocessing

Reproduce

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