Henrywood and Agarwal, Equation (13)

Percentage Accurate: 24.9% → 54.4%
Time: 45.4s
Alternatives: 5
Speedup: 30.2×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 5 alternatives:

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

Initial Program: 24.9% accurate, 1.0× speedup?

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

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

Alternative 1: 54.4% accurate, 0.2× 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\_0 \cdot \left(-0.5 \cdot \frac{{D}^{2} \cdot \left({M}^{2} \cdot \left(w \cdot h\right)\right)}{c0 \cdot {d}^{2}} + 2 \cdot \left(\frac{c0}{{D}^{2}} \cdot \frac{{d}^{2}}{w \cdot h}\right)\right)\\ \mathbf{elif}\;t\_2 \leq 0:\\ \;\;\;\;\mathsf{fma}\left(-0.5, 0, 0.25 \cdot \frac{{D}^{2} \cdot \left(h \cdot {M}^{2}\right)}{{d}^{2}}\right)\\ \mathbf{elif}\;t\_2 \leq \infty:\\ \;\;\;\;c0 \cdot \left({d}^{2} \cdot \frac{\frac{c0}{w}}{{D}^{2} \cdot \left(w \cdot h\right)}\right)\\ \mathbf{else}:\\ \;\;\;\;c0 \cdot \frac{0}{w}\\ \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_0
      (+
       (* -0.5 (/ (* (pow D 2.0) (* (pow M 2.0) (* w h))) (* c0 (pow d 2.0))))
       (* 2.0 (* (/ c0 (pow D 2.0)) (/ (pow d 2.0) (* w h))))))
     (if (<= t_2 0.0)
       (fma
        -0.5
        0.0
        (* 0.25 (/ (* (pow D 2.0) (* h (pow M 2.0))) (pow d 2.0))))
       (if (<= t_2 INFINITY)
         (* c0 (* (pow d 2.0) (/ (/ c0 w) (* (pow D 2.0) (* w h)))))
         (* c0 (/ 0.0 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_0 * ((-0.5 * ((pow(D, 2.0) * (pow(M, 2.0) * (w * h))) / (c0 * pow(d, 2.0)))) + (2.0 * ((c0 / pow(D, 2.0)) * (pow(d, 2.0) / (w * h)))));
	} else if (t_2 <= 0.0) {
		tmp = fma(-0.5, 0.0, (0.25 * ((pow(D, 2.0) * (h * pow(M, 2.0))) / pow(d, 2.0))));
	} else if (t_2 <= ((double) INFINITY)) {
		tmp = c0 * (pow(d, 2.0) * ((c0 / w) / (pow(D, 2.0) * (w * h))));
	} else {
		tmp = c0 * (0.0 / 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 <= Float64(-Inf))
		tmp = Float64(t_0 * Float64(Float64(-0.5 * Float64(Float64((D ^ 2.0) * Float64((M ^ 2.0) * Float64(w * h))) / Float64(c0 * (d ^ 2.0)))) + Float64(2.0 * Float64(Float64(c0 / (D ^ 2.0)) * Float64((d ^ 2.0) / Float64(w * h))))));
	elseif (t_2 <= 0.0)
		tmp = fma(-0.5, 0.0, Float64(0.25 * Float64(Float64((D ^ 2.0) * Float64(h * (M ^ 2.0))) / (d ^ 2.0))));
	elseif (t_2 <= Inf)
		tmp = Float64(c0 * Float64((d ^ 2.0) * Float64(Float64(c0 / w) / Float64((D ^ 2.0) * Float64(w * h)))));
	else
		tmp = Float64(c0 * Float64(0.0 / w));
	end
	return 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)], N[(t$95$0 * N[(N[(-0.5 * N[(N[(N[Power[D, 2.0], $MachinePrecision] * N[(N[Power[M, 2.0], $MachinePrecision] * N[(w * h), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(c0 * N[Power[d, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + 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]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 0.0], N[(-0.5 * 0.0 + N[(0.25 * N[(N[(N[Power[D, 2.0], $MachinePrecision] * N[(h * N[Power[M, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Power[d, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, Infinity], N[(c0 * N[(N[Power[d, 2.0], $MachinePrecision] * N[(N[(c0 / w), $MachinePrecision] / N[(N[Power[D, 2.0], $MachinePrecision] * N[(w * h), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(c0 * N[(0.0 / w), $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\_0 \cdot \left(-0.5 \cdot \frac{{D}^{2} \cdot \left({M}^{2} \cdot \left(w \cdot h\right)\right)}{c0 \cdot {d}^{2}} + 2 \cdot \left(\frac{c0}{{D}^{2}} \cdot \frac{{d}^{2}}{w \cdot h}\right)\right)\\

\mathbf{elif}\;t\_2 \leq 0:\\
\;\;\;\;\mathsf{fma}\left(-0.5, 0, 0.25 \cdot \frac{{D}^{2} \cdot \left(h \cdot {M}^{2}\right)}{{d}^{2}}\right)\\

\mathbf{elif}\;t\_2 \leq \infty:\\
\;\;\;\;c0 \cdot \left({d}^{2} \cdot \frac{\frac{c0}{w}}{{D}^{2} \cdot \left(w \cdot h\right)}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (*.f64 (/.f64 c0 (*.f64 2 w)) (+.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (sqrt.f64 (-.f64 (*.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D)))) (*.f64 M M))))) < -inf.0

    1. Initial program 80.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. Simplified80.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 c0 around inf 91.0%

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

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

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

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

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

    1. Initial program 64.8%

      \[\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \]
    2. Add Preprocessing
    3. Taylor expanded in c0 around -inf 63.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} + 0.25 \cdot \frac{{D}^{2} \cdot \left({M}^{2} \cdot h\right)}{{d}^{2}}} \]
    4. Step-by-step derivation
      1. fma-define63.5%

        \[\leadsto \color{blue}{\mathsf{fma}\left(-0.5, \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}, 0.25 \cdot \frac{{D}^{2} \cdot \left({M}^{2} \cdot h\right)}{{d}^{2}}\right)} \]
      2. associate-/l*63.5%

        \[\leadsto \mathsf{fma}\left(-0.5, \color{blue}{{c0}^{2} \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)}{{d}^{2}}\right) \]
      3. distribute-lft1-in63.5%

        \[\leadsto \mathsf{fma}\left(-0.5, {c0}^{2} \cdot \frac{\color{blue}{\left(-1 + 1\right) \cdot \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)}{{d}^{2}}\right) \]
      4. metadata-eval63.5%

        \[\leadsto \mathsf{fma}\left(-0.5, {c0}^{2} \cdot \frac{\color{blue}{0} \cdot \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)}{{d}^{2}}\right) \]
      5. mul0-lft64.2%

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

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

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

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

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

    1. Initial program 62.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. Simplified62.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto c0 \cdot \frac{{d}^{2} \cdot \frac{c0}{w}}{\color{blue}{\left(h \cdot {D}^{2}\right)} \cdot w} \]
    12. Applied egg-rr72.3%

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

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

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

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

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

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

    1. Initial program 0.0%

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

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (/.f64 c0 (*.f64 2 w)) (+.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (sqrt.f64 (-.f64 (*.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D)))) (*.f64 M M))))) < +inf.0

    1. Initial program 71.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. Simplified67.5%

      \[\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 76.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 0.0%

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

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

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

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

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

Alternative 3: 55.1% accurate, 0.5× 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}:\\ \;\;\;\;c0 \cdot \frac{0}{w}\\ \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 (* c0 (/ 0.0 w)))))
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 = c0 * (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)) / ((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 = c0 * (0.0 / w);
	}
	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 = c0 * (0.0 / w)
	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(c0 * Float64(0.0 / w));
	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 = c0 * (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[(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[(c0 * N[(0.0 / w), $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}:\\
\;\;\;\;c0 \cdot \frac{0}{w}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (/.f64 c0 (*.f64 2 w)) (+.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (sqrt.f64 (-.f64 (*.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D)))) (*.f64 M M))))) < +inf.0

    1. Initial program 71.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 2 w)) (+.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (sqrt.f64 (-.f64 (*.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D)))) (*.f64 M M)))))

    1. Initial program 0.0%

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

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

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

      \[\leadsto c0 \cdot \color{blue}{\frac{0}{w}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification56.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}:\\ \;\;\;\;c0 \cdot \frac{0}{w}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 33.5% accurate, 0.9× speedup?

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

\\
\begin{array}{l}
t_0 := \frac{c0}{w \cdot h}\\
t_1 := t\_0 \cdot \frac{d \cdot d}{D \cdot D}\\
\mathbf{if}\;D \leq 8 \cdot 10^{-212} \lor \neg \left(D \leq 1.15 \cdot 10^{-154}\right):\\
\;\;\;\;c0 \cdot \frac{0}{w}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if D < 7.99999999999999963e-212 or 1.15e-154 < D

    1. Initial program 19.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. Simplified29.0%

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

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

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

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

    if 7.99999999999999963e-212 < D < 1.15e-154

    1. Initial program 42.3%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;D \leq 8 \cdot 10^{-212} \lor \neg \left(D \leq 1.15 \cdot 10^{-154}\right):\\ \;\;\;\;c0 \cdot \frac{0}{w}\\ \mathbf{else}:\\ \;\;\;\;\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)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 34.4% accurate, 30.2× speedup?

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

\\
c0 \cdot \frac{0}{w}
\end{array}
Derivation
  1. Initial program 21.4%

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

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

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

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

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

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

Reproduce

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