Henrywood and Agarwal, Equation (13)

Percentage Accurate: 24.9% → 54.4%
Time: 30.5s
Alternatives: 9
Speedup: 0.5×

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 9 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: 54.4% 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(D \cdot D\right) \cdot \left(w \cdot h\right)}\\ \mathbf{if}\;t\_0 \cdot \left(t\_1 + \sqrt{t\_1 \cdot t\_1 - M \cdot M}\right) \leq \infty:\\ \;\;\;\;t\_0 \cdot \frac{2 \cdot \left(c0 \cdot {d}^{2}\right)}{{D}^{2} \cdot \left(w \cdot h\right)}\\ \mathbf{else}:\\ \;\;\;\;\log 1\\ \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)) (* (* D D) (* w h)))))
   (if (<= (* t_0 (+ t_1 (sqrt (- (* t_1 t_1) (* M M))))) INFINITY)
     (* t_0 (/ (* 2.0 (* c0 (pow d 2.0))) (* (pow D 2.0) (* w h))))
     (log 1.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)) / ((D * D) * (w * h));
	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))) / (pow(D, 2.0) * (w * h)));
	} else {
		tmp = log(1.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)) / ((D * D) * (w * h));
	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))) / (Math.pow(D, 2.0) * (w * h)));
	} else {
		tmp = Math.log(1.0);
	}
	return tmp;
}
def code(c0, w, h, D, d, M):
	t_0 = c0 / (2.0 * w)
	t_1 = (c0 * (d * d)) / ((D * D) * (w * h))
	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))) / (math.pow(D, 2.0) * (w * h)))
	else:
		tmp = math.log(1.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(D * D) * Float64(w * h)))
	tmp = 0.0
	if (Float64(t_0 * Float64(t_1 + sqrt(Float64(Float64(t_1 * t_1) - Float64(M * M))))) <= Inf)
		tmp = Float64(t_0 * Float64(Float64(2.0 * Float64(c0 * (d ^ 2.0))) / Float64((D ^ 2.0) * Float64(w * h))));
	else
		tmp = log(1.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)) / ((D * D) * (w * h));
	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))) / ((D ^ 2.0) * (w * h)));
	else
		tmp = log(1.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[(D * D), $MachinePrecision] * N[(w * h), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(t$95$0 * N[(t$95$1 + N[Sqrt[N[(N[(t$95$1 * t$95$1), $MachinePrecision] - N[(M * M), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], Infinity], N[(t$95$0 * N[(N[(2.0 * N[(c0 * N[Power[d, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[Power[D, 2.0], $MachinePrecision] * N[(w * h), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Log[1.0], $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(D \cdot D\right) \cdot \left(w \cdot h\right)}\\
\mathbf{if}\;t\_0 \cdot \left(t\_1 + \sqrt{t\_1 \cdot t\_1 - M \cdot M}\right) \leq \infty:\\
\;\;\;\;t\_0 \cdot \frac{2 \cdot \left(c0 \cdot {d}^{2}\right)}{{D}^{2} \cdot \left(w \cdot h\right)}\\

\mathbf{else}:\\
\;\;\;\;\log 1\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (/.f64 c0 (*.f64 #s(literal 2 binary64) 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 81.2%

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

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

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

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

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

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

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

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

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

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

      \[\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)} \]
    8. Step-by-step derivation
      1. associate-*r/84.8%

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

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

    if +inf.0 < (*.f64 (/.f64 c0 (*.f64 #s(literal 2 binary64) 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. Simplified23.7%

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

      \[\leadsto c0 \cdot \frac{\color{blue}{M \cdot \sqrt{-1}}}{2 \cdot w} \]
    5. Step-by-step derivation
      1. add-log-exp0.0%

        \[\leadsto \color{blue}{\log \left(e^{c0 \cdot \frac{M \cdot \sqrt{-1}}{2 \cdot w}}\right)} \]
      2. exp-prod21.7%

        \[\leadsto \log \color{blue}{\left({\left(e^{c0}\right)}^{\left(\frac{M \cdot \sqrt{-1}}{2 \cdot w}\right)}\right)} \]
      3. times-frac21.7%

        \[\leadsto \log \left({\left(e^{c0}\right)}^{\color{blue}{\left(\frac{M}{2} \cdot \frac{\sqrt{-1}}{w}\right)}}\right) \]
    6. Applied egg-rr21.7%

      \[\leadsto \color{blue}{\log \left({\left(e^{c0}\right)}^{\left(\frac{M}{2} \cdot \frac{\sqrt{-1}}{w}\right)}\right)} \]
    7. Taylor expanded in c0 around 0 44.6%

      \[\leadsto \log \left({\color{blue}{1}}^{\left(\frac{M}{2} \cdot \frac{\sqrt{-1}}{w}\right)}\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification57.0%

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

Alternative 2: 50.9% 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(D \cdot D\right) \cdot \left(w \cdot h\right)}\\ \mathbf{if}\;t\_0 \cdot \left(t\_1 + \sqrt{t\_1 \cdot t\_1 - M \cdot M}\right) \leq \infty:\\ \;\;\;\;t\_0 \cdot \frac{2 \cdot \left(c0 \cdot {d}^{2}\right)}{{D}^{2} \cdot \left(w \cdot h\right)}\\ \mathbf{else}:\\ \;\;\;\;-0.25 \cdot \left({\left(D \cdot M\right)}^{2} \cdot \left(h \cdot {d}^{-2}\right)\right)\\ \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)) (* (* D D) (* w h)))))
   (if (<= (* t_0 (+ t_1 (sqrt (- (* t_1 t_1) (* M M))))) INFINITY)
     (* t_0 (/ (* 2.0 (* c0 (pow d 2.0))) (* (pow D 2.0) (* w h))))
     (* -0.25 (* (pow (* D M) 2.0) (* h (pow 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)) / ((D * D) * (w * h));
	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))) / (pow(D, 2.0) * (w * h)));
	} else {
		tmp = -0.25 * (pow((D * M), 2.0) * (h * pow(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)) / ((D * D) * (w * h));
	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))) / (Math.pow(D, 2.0) * (w * h)));
	} else {
		tmp = -0.25 * (Math.pow((D * M), 2.0) * (h * Math.pow(d, -2.0)));
	}
	return tmp;
}
def code(c0, w, h, D, d, M):
	t_0 = c0 / (2.0 * w)
	t_1 = (c0 * (d * d)) / ((D * D) * (w * h))
	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))) / (math.pow(D, 2.0) * (w * h)))
	else:
		tmp = -0.25 * (math.pow((D * M), 2.0) * (h * math.pow(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(D * D) * Float64(w * h)))
	tmp = 0.0
	if (Float64(t_0 * Float64(t_1 + sqrt(Float64(Float64(t_1 * t_1) - Float64(M * M))))) <= Inf)
		tmp = Float64(t_0 * Float64(Float64(2.0 * Float64(c0 * (d ^ 2.0))) / Float64((D ^ 2.0) * Float64(w * h))));
	else
		tmp = Float64(-0.25 * Float64((Float64(D * M) ^ 2.0) * Float64(h * (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)) / ((D * D) * (w * h));
	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))) / ((D ^ 2.0) * (w * h)));
	else
		tmp = -0.25 * (((D * M) ^ 2.0) * (h * (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[(D * D), $MachinePrecision] * N[(w * h), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(t$95$0 * N[(t$95$1 + N[Sqrt[N[(N[(t$95$1 * t$95$1), $MachinePrecision] - N[(M * M), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], Infinity], N[(t$95$0 * N[(N[(2.0 * N[(c0 * N[Power[d, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[Power[D, 2.0], $MachinePrecision] * N[(w * h), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-0.25 * N[(N[Power[N[(D * M), $MachinePrecision], 2.0], $MachinePrecision] * N[(h * N[Power[d, -2.0], $MachinePrecision]), $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(D \cdot D\right) \cdot \left(w \cdot h\right)}\\
\mathbf{if}\;t\_0 \cdot \left(t\_1 + \sqrt{t\_1 \cdot t\_1 - M \cdot M}\right) \leq \infty:\\
\;\;\;\;t\_0 \cdot \frac{2 \cdot \left(c0 \cdot {d}^{2}\right)}{{D}^{2} \cdot \left(w \cdot h\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (/.f64 c0 (*.f64 #s(literal 2 binary64) 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 81.2%

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

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

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

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

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

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

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

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

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

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

      \[\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)} \]
    8. Step-by-step derivation
      1. associate-*r/84.8%

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

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

    if +inf.0 < (*.f64 (/.f64 c0 (*.f64 #s(literal 2 binary64) 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. Simplified3.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. Add Preprocessing
    4. Taylor expanded in h around 0 0.5%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto {\left(-0.25 \cdot \color{blue}{\left(\left({D}^{2} \cdot {M}^{2}\right) \cdot \frac{h}{{d}^{2}}\right)}\right)}^{1} \]
      3. pow-prod-down39.9%

        \[\leadsto {\left(-0.25 \cdot \left(\color{blue}{{\left(D \cdot M\right)}^{2}} \cdot \frac{h}{{d}^{2}}\right)\right)}^{1} \]
      4. div-inv39.9%

        \[\leadsto {\left(-0.25 \cdot \left({\left(D \cdot M\right)}^{2} \cdot \color{blue}{\left(h \cdot \frac{1}{{d}^{2}}\right)}\right)\right)}^{1} \]
      5. pow-flip39.9%

        \[\leadsto {\left(-0.25 \cdot \left({\left(D \cdot M\right)}^{2} \cdot \left(h \cdot \color{blue}{{d}^{\left(-2\right)}}\right)\right)\right)}^{1} \]
      6. metadata-eval39.9%

        \[\leadsto {\left(-0.25 \cdot \left({\left(D \cdot M\right)}^{2} \cdot \left(h \cdot {d}^{\color{blue}{-2}}\right)\right)\right)}^{1} \]
    11. Applied egg-rr39.9%

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

        \[\leadsto \color{blue}{-0.25 \cdot \left({\left(D \cdot M\right)}^{2} \cdot \left(h \cdot {d}^{-2}\right)\right)} \]
    13. Simplified39.9%

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

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

Alternative 3: 51.0% accurate, 0.4× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (/.f64 c0 (*.f64 #s(literal 2 binary64) 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 81.2%

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

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

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

    if +inf.0 < (*.f64 (/.f64 c0 (*.f64 #s(literal 2 binary64) 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. Simplified3.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. Add Preprocessing
    4. Taylor expanded in h around 0 0.5%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto {\left(-0.25 \cdot \color{blue}{\left(\left({D}^{2} \cdot {M}^{2}\right) \cdot \frac{h}{{d}^{2}}\right)}\right)}^{1} \]
      3. pow-prod-down39.9%

        \[\leadsto {\left(-0.25 \cdot \left(\color{blue}{{\left(D \cdot M\right)}^{2}} \cdot \frac{h}{{d}^{2}}\right)\right)}^{1} \]
      4. div-inv39.9%

        \[\leadsto {\left(-0.25 \cdot \left({\left(D \cdot M\right)}^{2} \cdot \color{blue}{\left(h \cdot \frac{1}{{d}^{2}}\right)}\right)\right)}^{1} \]
      5. pow-flip39.9%

        \[\leadsto {\left(-0.25 \cdot \left({\left(D \cdot M\right)}^{2} \cdot \left(h \cdot \color{blue}{{d}^{\left(-2\right)}}\right)\right)\right)}^{1} \]
      6. metadata-eval39.9%

        \[\leadsto {\left(-0.25 \cdot \left({\left(D \cdot M\right)}^{2} \cdot \left(h \cdot {d}^{\color{blue}{-2}}\right)\right)\right)}^{1} \]
    11. Applied egg-rr39.9%

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

        \[\leadsto \color{blue}{-0.25 \cdot \left({\left(D \cdot M\right)}^{2} \cdot \left(h \cdot {d}^{-2}\right)\right)} \]
    13. Simplified39.9%

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

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

Alternative 4: 51.4% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{c0 \cdot \left(d \cdot d\right)}{\left(D \cdot D\right) \cdot \left(w \cdot h\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 \left({\left(D \cdot M\right)}^{2} \cdot \left(h \cdot {d}^{-2}\right)\right)\\ \end{array} \end{array} \]
(FPCore (c0 w h D d M)
 :precision binary64
 (let* ((t_0 (/ (* c0 (* d d)) (* (* D D) (* w h))))
        (t_1 (* (/ c0 (* 2.0 w)) (+ t_0 (sqrt (- (* t_0 t_0) (* M M)))))))
   (if (<= t_1 INFINITY)
     t_1
     (* -0.25 (* (pow (* D M) 2.0) (* h (pow d -2.0)))))))
double code(double c0, double w, double h, double D, double d, double M) {
	double t_0 = (c0 * (d * d)) / ((D * D) * (w * h));
	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 * (pow((D * M), 2.0) * (h * pow(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)) / ((D * D) * (w * h));
	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 * (Math.pow((D * M), 2.0) * (h * Math.pow(d, -2.0)));
	}
	return tmp;
}
def code(c0, w, h, D, d, M):
	t_0 = (c0 * (d * d)) / ((D * D) * (w * h))
	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 * (math.pow((D * M), 2.0) * (h * math.pow(d, -2.0)))
	return tmp
function code(c0, w, h, D, d, M)
	t_0 = Float64(Float64(c0 * Float64(d * d)) / Float64(Float64(D * D) * Float64(w * h)))
	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(D * M) ^ 2.0) * Float64(h * (d ^ -2.0))));
	end
	return tmp
end
function tmp_2 = code(c0, w, h, D, d, M)
	t_0 = (c0 * (d * d)) / ((D * D) * (w * h));
	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 * (((D * M) ^ 2.0) * (h * (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[(D * D), $MachinePrecision] * N[(w * h), $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[Power[N[(D * M), $MachinePrecision], 2.0], $MachinePrecision] * N[(h * N[Power[d, -2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{c0 \cdot \left(d \cdot d\right)}{\left(D \cdot D\right) \cdot \left(w \cdot h\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 \left({\left(D \cdot M\right)}^{2} \cdot \left(h \cdot {d}^{-2}\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (/.f64 c0 (*.f64 #s(literal 2 binary64) 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 81.2%

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

    if +inf.0 < (*.f64 (/.f64 c0 (*.f64 #s(literal 2 binary64) 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. Simplified3.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. Add Preprocessing
    4. Taylor expanded in h around 0 0.5%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto {\left(-0.25 \cdot \color{blue}{\left(\left({D}^{2} \cdot {M}^{2}\right) \cdot \frac{h}{{d}^{2}}\right)}\right)}^{1} \]
      3. pow-prod-down39.9%

        \[\leadsto {\left(-0.25 \cdot \left(\color{blue}{{\left(D \cdot M\right)}^{2}} \cdot \frac{h}{{d}^{2}}\right)\right)}^{1} \]
      4. div-inv39.9%

        \[\leadsto {\left(-0.25 \cdot \left({\left(D \cdot M\right)}^{2} \cdot \color{blue}{\left(h \cdot \frac{1}{{d}^{2}}\right)}\right)\right)}^{1} \]
      5. pow-flip39.9%

        \[\leadsto {\left(-0.25 \cdot \left({\left(D \cdot M\right)}^{2} \cdot \left(h \cdot \color{blue}{{d}^{\left(-2\right)}}\right)\right)\right)}^{1} \]
      6. metadata-eval39.9%

        \[\leadsto {\left(-0.25 \cdot \left({\left(D \cdot M\right)}^{2} \cdot \left(h \cdot {d}^{\color{blue}{-2}}\right)\right)\right)}^{1} \]
    11. Applied egg-rr39.9%

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

        \[\leadsto \color{blue}{-0.25 \cdot \left({\left(D \cdot M\right)}^{2} \cdot \left(h \cdot {d}^{-2}\right)\right)} \]
    13. Simplified39.9%

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (/.f64 c0 (*.f64 #s(literal 2 binary64) 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 81.2%

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

    if +inf.0 < (*.f64 (/.f64 c0 (*.f64 #s(literal 2 binary64) 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. Simplified3.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. Add Preprocessing
    4. Applied egg-rr23.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 22.7% accurate, 1.0× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if M < 6.5000000000000001e-236

    1. Initial program 20.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. Simplified23.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. Add Preprocessing
    4. Step-by-step derivation
      1. times-frac22.4%

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

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

    if 6.5000000000000001e-236 < M

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;M \leq 6.5 \cdot 10^{-236}:\\ \;\;\;\;\frac{c0}{2 \cdot w} \cdot \left(\frac{c0}{w \cdot h} \cdot \left(\frac{d}{D} \cdot \frac{d}{D}\right) + \sqrt{\left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\right) \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\right) - M \cdot M}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{c0}{2 \cdot w} \cdot \left(\frac{d}{D} \cdot \sqrt{\frac{c0 \cdot M}{w \cdot h}}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 14.0% accurate, 1.2× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if D < 1.6e-222

    1. Initial program 24.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. Simplified26.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. Add Preprocessing
    4. Applied egg-rr42.4%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(\frac{d}{D} \cdot \sqrt{\color{blue}{\frac{M}{h} \cdot \frac{c0}{w}}}\right) \]
    10. Simplified16.0%

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

    if 1.6e-222 < D

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;D \leq 1.6 \cdot 10^{-222}:\\ \;\;\;\;\frac{c0}{2 \cdot w} \cdot \left(\frac{d}{D} \cdot \sqrt{\frac{M}{h} \cdot \frac{c0}{w}}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{c0}{2 \cdot w} \cdot \left(\frac{d}{D} \cdot \sqrt{\frac{c0 \cdot M}{w \cdot h}}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 13.9% accurate, 1.3× speedup?

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

\\
\frac{c0}{2 \cdot w} \cdot \left(\frac{d}{D} \cdot \sqrt{\frac{M}{h} \cdot \frac{c0}{w}}\right)
\end{array}
Derivation
  1. Initial program 25.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. Simplified26.6%

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{\left(\frac{d}{D} \cdot \sqrt{\frac{M}{h} \cdot \frac{c0}{w}}\right)} \]
  11. Add Preprocessing

Alternative 9: 0.0% accurate, 1.4× speedup?

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

\\
c0 \cdot \frac{M \cdot \sqrt{-1}}{2 \cdot w}
\end{array}
Derivation
  1. Initial program 25.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. Simplified41.1%

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

    \[\leadsto c0 \cdot \frac{\color{blue}{M \cdot \sqrt{-1}}}{2 \cdot w} \]
  5. Add Preprocessing

Reproduce

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