Henrywood and Agarwal, Equation (13)

Percentage Accurate: 24.5% → 61.6%
Time: 33.2s
Alternatives: 5
Speedup: 50.3×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 5 alternatives:

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

Initial Program: 24.5% accurate, 1.0× speedup?

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

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

Alternative 1: 61.6% accurate, 0.4× speedup?

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

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

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

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

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

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

        \[\leadsto {c0}^{2} \cdot \left(\frac{-0.5 \cdot \left(\color{blue}{0} \cdot \frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)}{w} + 0.25 \cdot \frac{{D}^{2} \cdot \left({M}^{2} \cdot h\right)}{{c0}^{2} \cdot {d}^{2}}\right) \]
      4. mul0-lft17.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 54.6% accurate, 0.5× speedup?

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

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

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


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

      \[\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \]
    2. 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. Add Preprocessing
    3. Step-by-step derivation
      1. associate-*r*0.0%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(\frac{\color{blue}{\left(c0 \cdot d\right) \cdot d}}{\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. associate-*r*0.0%

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{0} \cdot -0.5}{w} \]
      7. metadata-eval46.5%

        \[\leadsto \frac{\color{blue}{0}}{w} \]
    7. Simplified46.5%

      \[\leadsto \color{blue}{\frac{0}{w}} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 3: 32.5% accurate, 0.9× 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)}\\ \mathbf{if}\;D \leq 4.4 \cdot 10^{-189} \lor \neg \left(D \leq 7 \cdot 10^{-166}\right) \land \left(D \leq 7.5 \cdot 10^{-139} \lor \neg \left(D \leq 5.5 \cdot 10^{-130}\right) \land D \leq 4.6 \cdot 10^{-21}\right):\\ \;\;\;\;\frac{0}{w}\\ \mathbf{else}:\\ \;\;\;\;\frac{c0}{2 \cdot w} \cdot \left(\sqrt{t\_0 \cdot t\_0 - M \cdot M} + \frac{d}{D} \cdot \left(c0 \cdot \frac{\frac{d}{D}}{w \cdot h}\right)\right)\\ \end{array} \end{array} \]
(FPCore (c0 w h D d M)
 :precision binary64
 (let* ((t_0 (/ (* c0 (* d d)) (* (* w h) (* D D)))))
   (if (or (<= D 4.4e-189)
           (and (not (<= D 7e-166))
                (or (<= D 7.5e-139)
                    (and (not (<= D 5.5e-130)) (<= D 4.6e-21)))))
     (/ 0.0 w)
     (*
      (/ c0 (* 2.0 w))
      (+
       (sqrt (- (* t_0 t_0) (* M M)))
       (* (/ d D) (* c0 (/ (/ d D) (* w h)))))))))
double code(double c0, double w, double h, double D, double d, double M) {
	double t_0 = (c0 * (d * d)) / ((w * h) * (D * D));
	double tmp;
	if ((D <= 4.4e-189) || (!(D <= 7e-166) && ((D <= 7.5e-139) || (!(D <= 5.5e-130) && (D <= 4.6e-21))))) {
		tmp = 0.0 / w;
	} else {
		tmp = (c0 / (2.0 * w)) * (sqrt(((t_0 * t_0) - (M * M))) + ((d / D) * (c0 * ((d / D) / (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 * (d_1 * d_1)) / ((w * h) * (d * d))
    if ((d <= 4.4d-189) .or. (.not. (d <= 7d-166)) .and. (d <= 7.5d-139) .or. (.not. (d <= 5.5d-130)) .and. (d <= 4.6d-21)) then
        tmp = 0.0d0 / w
    else
        tmp = (c0 / (2.0d0 * w)) * (sqrt(((t_0 * t_0) - (m * m))) + ((d_1 / d) * (c0 * ((d_1 / d) / (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 * (d * d)) / ((w * h) * (D * D));
	double tmp;
	if ((D <= 4.4e-189) || (!(D <= 7e-166) && ((D <= 7.5e-139) || (!(D <= 5.5e-130) && (D <= 4.6e-21))))) {
		tmp = 0.0 / w;
	} else {
		tmp = (c0 / (2.0 * w)) * (Math.sqrt(((t_0 * t_0) - (M * M))) + ((d / D) * (c0 * ((d / D) / (w * h)))));
	}
	return tmp;
}
def code(c0, w, h, D, d, M):
	t_0 = (c0 * (d * d)) / ((w * h) * (D * D))
	tmp = 0
	if (D <= 4.4e-189) or (not (D <= 7e-166) and ((D <= 7.5e-139) or (not (D <= 5.5e-130) and (D <= 4.6e-21)))):
		tmp = 0.0 / w
	else:
		tmp = (c0 / (2.0 * w)) * (math.sqrt(((t_0 * t_0) - (M * M))) + ((d / D) * (c0 * ((d / D) / (w * h)))))
	return tmp
function code(c0, w, h, D, d, M)
	t_0 = Float64(Float64(c0 * Float64(d * d)) / Float64(Float64(w * h) * Float64(D * D)))
	tmp = 0.0
	if ((D <= 4.4e-189) || (!(D <= 7e-166) && ((D <= 7.5e-139) || (!(D <= 5.5e-130) && (D <= 4.6e-21)))))
		tmp = Float64(0.0 / w);
	else
		tmp = Float64(Float64(c0 / Float64(2.0 * w)) * Float64(sqrt(Float64(Float64(t_0 * t_0) - Float64(M * M))) + Float64(Float64(d / D) * Float64(c0 * Float64(Float64(d / D) / Float64(w * h))))));
	end
	return tmp
end
function tmp_2 = code(c0, w, h, D, d, M)
	t_0 = (c0 * (d * d)) / ((w * h) * (D * D));
	tmp = 0.0;
	if ((D <= 4.4e-189) || (~((D <= 7e-166)) && ((D <= 7.5e-139) || (~((D <= 5.5e-130)) && (D <= 4.6e-21)))))
		tmp = 0.0 / w;
	else
		tmp = (c0 / (2.0 * w)) * (sqrt(((t_0 * t_0) - (M * M))) + ((d / D) * (c0 * ((d / D) / (w * h)))));
	end
	tmp_2 = tmp;
end
code[c0_, w_, h_, D_, d_, M_] := Block[{t$95$0 = N[(N[(c0 * N[(d * d), $MachinePrecision]), $MachinePrecision] / N[(N[(w * h), $MachinePrecision] * N[(D * D), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[D, 4.4e-189], And[N[Not[LessEqual[D, 7e-166]], $MachinePrecision], Or[LessEqual[D, 7.5e-139], And[N[Not[LessEqual[D, 5.5e-130]], $MachinePrecision], LessEqual[D, 4.6e-21]]]]], N[(0.0 / w), $MachinePrecision], N[(N[(c0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision] * N[(N[Sqrt[N[(N[(t$95$0 * t$95$0), $MachinePrecision] - N[(M * M), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + N[(N[(d / D), $MachinePrecision] * N[(c0 * N[(N[(d / D), $MachinePrecision] / N[(w * h), $MachinePrecision]), $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)}\\
\mathbf{if}\;D \leq 4.4 \cdot 10^{-189} \lor \neg \left(D \leq 7 \cdot 10^{-166}\right) \land \left(D \leq 7.5 \cdot 10^{-139} \lor \neg \left(D \leq 5.5 \cdot 10^{-130}\right) \land D \leq 4.6 \cdot 10^{-21}\right):\\
\;\;\;\;\frac{0}{w}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if D < 4.40000000000000038e-189 or 6.9999999999999998e-166 < D < 7.5000000000000001e-139 or 5.50000000000000007e-130 < D < 4.59999999999999999e-21

    1. Initial program 20.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. Add Preprocessing
    3. Step-by-step derivation
      1. associate-*r*19.6%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(\frac{\color{blue}{\left(c0 \cdot d\right) \cdot d}}{\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. associate-*r*19.6%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\left({c0}^{2} \cdot \color{blue}{0}\right) \cdot -0.5}{w} \]
      6. mul0-rgt40.9%

        \[\leadsto \frac{\color{blue}{0} \cdot -0.5}{w} \]
      7. metadata-eval40.9%

        \[\leadsto \frac{\color{blue}{0}}{w} \]
    7. Simplified40.9%

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

    if 4.40000000000000038e-189 < D < 6.9999999999999998e-166 or 7.5000000000000001e-139 < D < 5.50000000000000007e-130 or 4.59999999999999999e-21 < D

    1. Initial program 42.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. Add Preprocessing
    3. Step-by-step derivation
      1. associate-*r*42.7%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(\frac{\color{blue}{\left(c0 \cdot d\right) \cdot d}}{\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. associate-*r*42.7%

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;D \leq 4.4 \cdot 10^{-189} \lor \neg \left(D \leq 7 \cdot 10^{-166}\right) \land \left(D \leq 7.5 \cdot 10^{-139} \lor \neg \left(D \leq 5.5 \cdot 10^{-130}\right) \land D \leq 4.6 \cdot 10^{-21}\right):\\ \;\;\;\;\frac{0}{w}\\ \mathbf{else}:\\ \;\;\;\;\frac{c0}{2 \cdot w} \cdot \left(\sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M} + \frac{d}{D} \cdot \left(c0 \cdot \frac{\frac{d}{D}}{w \cdot h}\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 32.6% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{c0}{2 \cdot w}\\ t_1 := \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}\\ t_2 := \sqrt{t\_1 \cdot t\_1 - M \cdot M}\\ \mathbf{if}\;D \leq 5.3 \cdot 10^{-189}:\\ \;\;\;\;\frac{0}{w}\\ \mathbf{elif}\;D \leq 10^{-165}:\\ \;\;\;\;t\_0 \cdot \left(t\_2 + \frac{d}{D} \cdot \left(c0 \cdot \frac{\frac{d}{D}}{w \cdot h}\right)\right)\\ \mathbf{elif}\;D \leq 7.5 \cdot 10^{-139} \lor \neg \left(D \leq 1.7 \cdot 10^{-129}\right) \land D \leq 1.1 \cdot 10^{-19}:\\ \;\;\;\;\frac{0}{w}\\ \mathbf{else}:\\ \;\;\;\;t\_0 \cdot \left(t\_2 + \frac{d}{D} \cdot \frac{c0 \cdot d}{\left(w \cdot h\right) \cdot D}\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)) (* (* w h) (* D D))))
        (t_2 (sqrt (- (* t_1 t_1) (* M M)))))
   (if (<= D 5.3e-189)
     (/ 0.0 w)
     (if (<= D 1e-165)
       (* t_0 (+ t_2 (* (/ d D) (* c0 (/ (/ d D) (* w h))))))
       (if (or (<= D 7.5e-139) (and (not (<= D 1.7e-129)) (<= D 1.1e-19)))
         (/ 0.0 w)
         (* t_0 (+ t_2 (* (/ d D) (/ (* c0 d) (* (* w h) D))))))))))
double code(double c0, double w, double h, double D, double d, double M) {
	double t_0 = c0 / (2.0 * w);
	double t_1 = (c0 * (d * d)) / ((w * h) * (D * D));
	double t_2 = sqrt(((t_1 * t_1) - (M * M)));
	double tmp;
	if (D <= 5.3e-189) {
		tmp = 0.0 / w;
	} else if (D <= 1e-165) {
		tmp = t_0 * (t_2 + ((d / D) * (c0 * ((d / D) / (w * h)))));
	} else if ((D <= 7.5e-139) || (!(D <= 1.7e-129) && (D <= 1.1e-19))) {
		tmp = 0.0 / w;
	} else {
		tmp = t_0 * (t_2 + ((d / D) * ((c0 * d) / ((w * h) * D))));
	}
	return tmp;
}
real(8) function code(c0, w, h, d, d_1, m)
    real(8), intent (in) :: c0
    real(8), intent (in) :: w
    real(8), intent (in) :: h
    real(8), intent (in) :: d
    real(8), intent (in) :: d_1
    real(8), intent (in) :: m
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_0 = c0 / (2.0d0 * w)
    t_1 = (c0 * (d_1 * d_1)) / ((w * h) * (d * d))
    t_2 = sqrt(((t_1 * t_1) - (m * m)))
    if (d <= 5.3d-189) then
        tmp = 0.0d0 / w
    else if (d <= 1d-165) then
        tmp = t_0 * (t_2 + ((d_1 / d) * (c0 * ((d_1 / d) / (w * h)))))
    else if ((d <= 7.5d-139) .or. (.not. (d <= 1.7d-129)) .and. (d <= 1.1d-19)) then
        tmp = 0.0d0 / w
    else
        tmp = t_0 * (t_2 + ((d_1 / d) * ((c0 * d_1) / ((w * h) * d))))
    end if
    code = tmp
end function
public static double code(double c0, double w, double h, double D, double d, double M) {
	double t_0 = c0 / (2.0 * w);
	double t_1 = (c0 * (d * d)) / ((w * h) * (D * D));
	double t_2 = Math.sqrt(((t_1 * t_1) - (M * M)));
	double tmp;
	if (D <= 5.3e-189) {
		tmp = 0.0 / w;
	} else if (D <= 1e-165) {
		tmp = t_0 * (t_2 + ((d / D) * (c0 * ((d / D) / (w * h)))));
	} else if ((D <= 7.5e-139) || (!(D <= 1.7e-129) && (D <= 1.1e-19))) {
		tmp = 0.0 / w;
	} else {
		tmp = t_0 * (t_2 + ((d / D) * ((c0 * d) / ((w * h) * D))));
	}
	return tmp;
}
def code(c0, w, h, D, d, M):
	t_0 = c0 / (2.0 * w)
	t_1 = (c0 * (d * d)) / ((w * h) * (D * D))
	t_2 = math.sqrt(((t_1 * t_1) - (M * M)))
	tmp = 0
	if D <= 5.3e-189:
		tmp = 0.0 / w
	elif D <= 1e-165:
		tmp = t_0 * (t_2 + ((d / D) * (c0 * ((d / D) / (w * h)))))
	elif (D <= 7.5e-139) or (not (D <= 1.7e-129) and (D <= 1.1e-19)):
		tmp = 0.0 / w
	else:
		tmp = t_0 * (t_2 + ((d / D) * ((c0 * d) / ((w * h) * D))))
	return tmp
function code(c0, w, h, D, d, M)
	t_0 = Float64(c0 / Float64(2.0 * w))
	t_1 = Float64(Float64(c0 * Float64(d * d)) / Float64(Float64(w * h) * Float64(D * D)))
	t_2 = sqrt(Float64(Float64(t_1 * t_1) - Float64(M * M)))
	tmp = 0.0
	if (D <= 5.3e-189)
		tmp = Float64(0.0 / w);
	elseif (D <= 1e-165)
		tmp = Float64(t_0 * Float64(t_2 + Float64(Float64(d / D) * Float64(c0 * Float64(Float64(d / D) / Float64(w * h))))));
	elseif ((D <= 7.5e-139) || (!(D <= 1.7e-129) && (D <= 1.1e-19)))
		tmp = Float64(0.0 / w);
	else
		tmp = Float64(t_0 * Float64(t_2 + Float64(Float64(d / D) * Float64(Float64(c0 * d) / Float64(Float64(w * h) * D)))));
	end
	return tmp
end
function tmp_2 = code(c0, w, h, D, d, M)
	t_0 = c0 / (2.0 * w);
	t_1 = (c0 * (d * d)) / ((w * h) * (D * D));
	t_2 = sqrt(((t_1 * t_1) - (M * M)));
	tmp = 0.0;
	if (D <= 5.3e-189)
		tmp = 0.0 / w;
	elseif (D <= 1e-165)
		tmp = t_0 * (t_2 + ((d / D) * (c0 * ((d / D) / (w * h)))));
	elseif ((D <= 7.5e-139) || (~((D <= 1.7e-129)) && (D <= 1.1e-19)))
		tmp = 0.0 / w;
	else
		tmp = t_0 * (t_2 + ((d / D) * ((c0 * d) / ((w * h) * D))));
	end
	tmp_2 = tmp;
end
code[c0_, w_, h_, D_, d_, M_] := Block[{t$95$0 = N[(c0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(c0 * N[(d * d), $MachinePrecision]), $MachinePrecision] / N[(N[(w * h), $MachinePrecision] * N[(D * D), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Sqrt[N[(N[(t$95$1 * t$95$1), $MachinePrecision] - N[(M * M), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[D, 5.3e-189], N[(0.0 / w), $MachinePrecision], If[LessEqual[D, 1e-165], N[(t$95$0 * N[(t$95$2 + N[(N[(d / D), $MachinePrecision] * N[(c0 * N[(N[(d / D), $MachinePrecision] / N[(w * h), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[D, 7.5e-139], And[N[Not[LessEqual[D, 1.7e-129]], $MachinePrecision], LessEqual[D, 1.1e-19]]], N[(0.0 / w), $MachinePrecision], N[(t$95$0 * N[(t$95$2 + N[(N[(d / D), $MachinePrecision] * N[(N[(c0 * d), $MachinePrecision] / N[(N[(w * h), $MachinePrecision] * D), $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(w \cdot h\right) \cdot \left(D \cdot D\right)}\\
t_2 := \sqrt{t\_1 \cdot t\_1 - M \cdot M}\\
\mathbf{if}\;D \leq 5.3 \cdot 10^{-189}:\\
\;\;\;\;\frac{0}{w}\\

\mathbf{elif}\;D \leq 10^{-165}:\\
\;\;\;\;t\_0 \cdot \left(t\_2 + \frac{d}{D} \cdot \left(c0 \cdot \frac{\frac{d}{D}}{w \cdot h}\right)\right)\\

\mathbf{elif}\;D \leq 7.5 \cdot 10^{-139} \lor \neg \left(D \leq 1.7 \cdot 10^{-129}\right) \land D \leq 1.1 \cdot 10^{-19}:\\
\;\;\;\;\frac{0}{w}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if D < 5.2999999999999998e-189 or 1e-165 < D < 7.5000000000000001e-139 or 1.70000000000000007e-129 < D < 1.0999999999999999e-19

    1. Initial program 20.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. Add Preprocessing
    3. Step-by-step derivation
      1. associate-*r*19.6%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(\frac{\color{blue}{\left(c0 \cdot d\right) \cdot d}}{\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. associate-*r*19.6%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\left({c0}^{2} \cdot \color{blue}{0}\right) \cdot -0.5}{w} \]
      6. mul0-rgt40.9%

        \[\leadsto \frac{\color{blue}{0} \cdot -0.5}{w} \]
      7. metadata-eval40.9%

        \[\leadsto \frac{\color{blue}{0}}{w} \]
    7. Simplified40.9%

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

    if 5.2999999999999998e-189 < D < 1e-165

    1. Initial program 100.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. Add Preprocessing
    3. Step-by-step derivation
      1. associate-*r*100.0%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(\frac{\color{blue}{\left(c0 \cdot d\right) \cdot d}}{\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. associate-*r*100.0%

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

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

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

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

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

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

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

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

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

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

    if 7.5000000000000001e-139 < D < 1.70000000000000007e-129 or 1.0999999999999999e-19 < D

    1. Initial program 36.5%

      \[\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. associate-*r*37.0%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(\frac{\color{blue}{\left(c0 \cdot d\right) \cdot d}}{\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. associate-*r*37.0%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;D \leq 5.3 \cdot 10^{-189}:\\ \;\;\;\;\frac{0}{w}\\ \mathbf{elif}\;D \leq 10^{-165}:\\ \;\;\;\;\frac{c0}{2 \cdot w} \cdot \left(\sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M} + \frac{d}{D} \cdot \left(c0 \cdot \frac{\frac{d}{D}}{w \cdot h}\right)\right)\\ \mathbf{elif}\;D \leq 7.5 \cdot 10^{-139} \lor \neg \left(D \leq 1.7 \cdot 10^{-129}\right) \land D \leq 1.1 \cdot 10^{-19}:\\ \;\;\;\;\frac{0}{w}\\ \mathbf{else}:\\ \;\;\;\;\frac{c0}{2 \cdot w} \cdot \left(\sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M} + \frac{d}{D} \cdot \frac{c0 \cdot d}{\left(w \cdot h\right) \cdot D}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 33.6% accurate, 50.3× speedup?

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

\\
\frac{0}{w}
\end{array}
Derivation
  1. Initial program 24.9%

    \[\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. associate-*r*24.7%

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(\frac{\color{blue}{\left(c0 \cdot d\right) \cdot d}}{\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. associate-*r*24.7%

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\left({c0}^{2} \cdot \color{blue}{0}\right) \cdot -0.5}{w} \]
    6. mul0-rgt36.7%

      \[\leadsto \frac{\color{blue}{0} \cdot -0.5}{w} \]
    7. metadata-eval36.7%

      \[\leadsto \frac{\color{blue}{0}}{w} \]
  7. Simplified36.7%

    \[\leadsto \color{blue}{\frac{0}{w}} \]
  8. Add Preprocessing

Reproduce

?
herbie shell --seed 2024096 
(FPCore (c0 w h D d M)
  :name "Henrywood and Agarwal, Equation (13)"
  :precision binary64
  (* (/ c0 (* 2.0 w)) (+ (/ (* c0 (* d d)) (* (* w h) (* D D))) (sqrt (- (* (/ (* c0 (* d d)) (* (* w h) (* D D))) (/ (* c0 (* d d)) (* (* w h) (* D D)))) (* M M))))))