Henrywood and Agarwal, Equation (13)

Percentage Accurate: 24.9% → 61.9%
Time: 29.4s
Alternatives: 5
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 5 alternatives:

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

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

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

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

\mathbf{elif}\;t_4 \leq 0:\\
\;\;\;\;-0.5 \cdot \left(-0.5 \cdot \frac{h \cdot \left({D}^{2} \cdot {M}^{2}\right)}{{d}^{2}}\right)\\

\mathbf{elif}\;t_4 \leq \infty:\\
\;\;\;\;t_2\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 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))))) < -4.9999999999999998e-95 or -0.0 < (*.f64 (/.f64 c0 (*.f64 2 w)) (+.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (sqrt.f64 (-.f64 (*.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D)))) (*.f64 M M))))) < +inf.0

    1. Initial program 77.5%

      \[\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \]
    2. Simplified76.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. Taylor expanded in c0 around inf 78.7%

      \[\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)} \]
    4. Step-by-step derivation
      1. *-commutative78.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -4.9999999999999998e-95 < (*.f64 (/.f64 c0 (*.f64 2 w)) (+.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (sqrt.f64 (-.f64 (*.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D)))) (*.f64 M M))))) < -0.0

    1. Initial program 59.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. Simplified59.4%

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

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

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

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

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

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

      \[\leadsto \color{blue}{-0.5 \cdot \frac{{M}^{2}}{w \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)}} \]
    7. Step-by-step derivation
      1. associate-/r*54.3%

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

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

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

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

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

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

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

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

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

        \[\leadsto -0.5 \cdot \left(-0.5 \cdot \frac{h \cdot \color{blue}{\left({D}^{2} \cdot {M}^{2}\right)}}{{d}^{2}}\right) \]
    11. Simplified68.6%

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

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

    1. Initial program 0.0%

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

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

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

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

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

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

      \[\leadsto \color{blue}{-0.5 \cdot \frac{{M}^{2}}{w \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)}} \]
    7. Step-by-step derivation
      1. associate-/r*27.5%

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

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

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

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

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

      \[\leadsto -0.5 \cdot \color{blue}{\frac{{M}^{2}}{-1 \cdot \frac{{d}^{2}}{{D}^{2} \cdot h} - \frac{{d}^{2}}{{D}^{2} \cdot h}}} \]
    10. Step-by-step derivation
      1. sub-neg42.9%

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

        \[\leadsto -0.5 \cdot \frac{{M}^{2}}{-1 \cdot \frac{{d}^{2}}{{D}^{2} \cdot h} + \color{blue}{-1 \cdot \frac{{d}^{2}}{{D}^{2} \cdot h}}} \]
      3. distribute-rgt-out42.9%

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

        \[\leadsto -0.5 \cdot \frac{{M}^{2}}{\color{blue}{\frac{\frac{{d}^{2}}{{D}^{2}}}{h}} \cdot \left(-1 + -1\right)} \]
      5. unpow243.3%

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

        \[\leadsto -0.5 \cdot \frac{{M}^{2}}{\frac{\frac{d \cdot d}{\color{blue}{D \cdot D}}}{h} \cdot \left(-1 + -1\right)} \]
      7. times-frac51.0%

        \[\leadsto -0.5 \cdot \frac{{M}^{2}}{\frac{\color{blue}{\frac{d}{D} \cdot \frac{d}{D}}}{h} \cdot \left(-1 + -1\right)} \]
      8. unpow251.0%

        \[\leadsto -0.5 \cdot \frac{{M}^{2}}{\frac{\color{blue}{{\left(\frac{d}{D}\right)}^{2}}}{h} \cdot \left(-1 + -1\right)} \]
      9. metadata-eval51.0%

        \[\leadsto -0.5 \cdot \frac{{M}^{2}}{\frac{{\left(\frac{d}{D}\right)}^{2}}{h} \cdot \color{blue}{-2}} \]
    11. Simplified51.0%

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

Alternative 2: 60.7% accurate, 0.4× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{{M}^{2}}{\frac{{\left(\frac{d}{D}\right)}^{2}}{h} \cdot -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 74.4%

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

      \[\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. Taylor expanded in c0 around inf 71.9%

      \[\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)} \]
    4. Step-by-step derivation
      1. *-commutative71.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-0.5 \cdot \frac{{M}^{2}}{w \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)}} \]
    7. Step-by-step derivation
      1. associate-/r*27.5%

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

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

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

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

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

      \[\leadsto -0.5 \cdot \color{blue}{\frac{{M}^{2}}{-1 \cdot \frac{{d}^{2}}{{D}^{2} \cdot h} - \frac{{d}^{2}}{{D}^{2} \cdot h}}} \]
    10. Step-by-step derivation
      1. sub-neg42.9%

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

        \[\leadsto -0.5 \cdot \frac{{M}^{2}}{-1 \cdot \frac{{d}^{2}}{{D}^{2} \cdot h} + \color{blue}{-1 \cdot \frac{{d}^{2}}{{D}^{2} \cdot h}}} \]
      3. distribute-rgt-out42.9%

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

        \[\leadsto -0.5 \cdot \frac{{M}^{2}}{\color{blue}{\frac{\frac{{d}^{2}}{{D}^{2}}}{h}} \cdot \left(-1 + -1\right)} \]
      5. unpow243.3%

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

        \[\leadsto -0.5 \cdot \frac{{M}^{2}}{\frac{\frac{d \cdot d}{\color{blue}{D \cdot D}}}{h} \cdot \left(-1 + -1\right)} \]
      7. times-frac51.0%

        \[\leadsto -0.5 \cdot \frac{{M}^{2}}{\frac{\color{blue}{\frac{d}{D} \cdot \frac{d}{D}}}{h} \cdot \left(-1 + -1\right)} \]
      8. unpow251.0%

        \[\leadsto -0.5 \cdot \frac{{M}^{2}}{\frac{\color{blue}{{\left(\frac{d}{D}\right)}^{2}}}{h} \cdot \left(-1 + -1\right)} \]
      9. metadata-eval51.0%

        \[\leadsto -0.5 \cdot \frac{{M}^{2}}{\frac{{\left(\frac{d}{D}\right)}^{2}}{h} \cdot \color{blue}{-2}} \]
    11. Simplified51.0%

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

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

Alternative 3: 54.7% accurate, 0.9× speedup?

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

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

\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 74.4%

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

      \[\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. Taylor expanded in c0 around inf 71.9%

      \[\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)} \]
    4. Step-by-step derivation
      1. *-commutative71.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\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)} \]
    4. Step-by-step derivation
      1. mul-1-neg1.9%

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

        \[\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) \]
    5. Simplified32.8%

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

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

    \[\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{\frac{\frac{c0}{w}}{h}}{\frac{1}{\frac{d}{D}} \cdot \frac{1}{\frac{d}{D}}}\right)\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]

Alternative 4: 43.7% accurate, 6.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;w \leq 8.5 \cdot 10^{+98}:\\ \;\;\;\;\frac{c0}{2 \cdot w} \cdot \left(2 \cdot \frac{\frac{c0}{w \cdot h}}{\frac{1}{\frac{d}{D}} \cdot \frac{D}{d}}\right)\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \end{array} \]
(FPCore (c0 w h D d M)
 :precision binary64
 (if (<= w 8.5e+98)
   (* (/ c0 (* 2.0 w)) (* 2.0 (/ (/ c0 (* w h)) (* (/ 1.0 (/ d D)) (/ D d)))))
   0.0))
double code(double c0, double w, double h, double D, double d, double M) {
	double tmp;
	if (w <= 8.5e+98) {
		tmp = (c0 / (2.0 * w)) * (2.0 * ((c0 / (w * h)) / ((1.0 / (d / D)) * (D / d))));
	} 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) :: tmp
    if (w <= 8.5d+98) then
        tmp = (c0 / (2.0d0 * w)) * (2.0d0 * ((c0 / (w * h)) / ((1.0d0 / (d_1 / d)) * (d / d_1))))
    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 tmp;
	if (w <= 8.5e+98) {
		tmp = (c0 / (2.0 * w)) * (2.0 * ((c0 / (w * h)) / ((1.0 / (d / D)) * (D / d))));
	} else {
		tmp = 0.0;
	}
	return tmp;
}
def code(c0, w, h, D, d, M):
	tmp = 0
	if w <= 8.5e+98:
		tmp = (c0 / (2.0 * w)) * (2.0 * ((c0 / (w * h)) / ((1.0 / (d / D)) * (D / d))))
	else:
		tmp = 0.0
	return tmp
function code(c0, w, h, D, d, M)
	tmp = 0.0
	if (w <= 8.5e+98)
		tmp = Float64(Float64(c0 / Float64(2.0 * w)) * Float64(2.0 * Float64(Float64(c0 / Float64(w * h)) / Float64(Float64(1.0 / Float64(d / D)) * Float64(D / d)))));
	else
		tmp = 0.0;
	end
	return tmp
end
function tmp_2 = code(c0, w, h, D, d, M)
	tmp = 0.0;
	if (w <= 8.5e+98)
		tmp = (c0 / (2.0 * w)) * (2.0 * ((c0 / (w * h)) / ((1.0 / (d / D)) * (D / d))));
	else
		tmp = 0.0;
	end
	tmp_2 = tmp;
end
code[c0_, w_, h_, D_, d_, M_] := If[LessEqual[w, 8.5e+98], N[(N[(c0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision] * N[(2.0 * N[(N[(c0 / N[(w * h), $MachinePrecision]), $MachinePrecision] / N[(N[(1.0 / N[(d / D), $MachinePrecision]), $MachinePrecision] * N[(D / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.0]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;w \leq 8.5 \cdot 10^{+98}:\\
\;\;\;\;\frac{c0}{2 \cdot w} \cdot \left(2 \cdot \frac{\frac{c0}{w \cdot h}}{\frac{1}{\frac{d}{D}} \cdot \frac{D}{d}}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if w < 8.4999999999999996e98

    1. Initial program 28.8%

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

      \[\leadsto \color{blue}{\frac{c0}{2 \cdot w} \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D} + \sqrt{\left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\right) \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\right) - M \cdot M}\right)} \]
    3. Taylor expanded in c0 around inf 37.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)} \]
    4. Step-by-step derivation
      1. *-commutative37.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(2 \cdot \frac{\frac{c0}{h \cdot w}}{\color{blue}{\frac{1}{\frac{d}{D}} \cdot \frac{1}{\frac{d}{D}}}}\right) \]
    12. Taylor expanded in d around 0 46.9%

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

    if 8.4999999999999996e98 < w

    1. Initial program 16.9%

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

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

      \[\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)} \]
    4. Step-by-step derivation
      1. mul-1-neg11.9%

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

        \[\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) \]
    5. Simplified45.5%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;w \leq 8.5 \cdot 10^{+98}:\\ \;\;\;\;\frac{c0}{2 \cdot w} \cdot \left(2 \cdot \frac{\frac{c0}{w \cdot h}}{\frac{1}{\frac{d}{D}} \cdot \frac{D}{d}}\right)\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]

Alternative 5: 33.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.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. Simplified27.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. Taylor expanded in c0 around -inf 5.1%

    \[\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)} \]
  4. Step-by-step derivation
    1. mul-1-neg5.1%

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

      \[\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) \]
  5. Simplified25.7%

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

    \[\leadsto \color{blue}{0} \]
  7. Final simplification30.6%

    \[\leadsto 0 \]

Reproduce

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