Henrywood and Agarwal, Equation (13)

Percentage Accurate: 24.5% → 46.4%
Time: 31.5s
Alternatives: 8
Speedup: 21.6×

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 8 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: 46.4% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;h \leq -9.4 \cdot 10^{-308}:\\
\;\;\;\;\left(c0 \cdot 2\right) \cdot \left(\left({\left(\frac{d}{D}\right)}^{2} \cdot \frac{\frac{c0}{w}}{h}\right) \cdot \frac{0.5}{w}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if h < -9.4000000000000009e-308

    1. Initial program 22.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. Simplified37.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 w around 0 4.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -9.4000000000000009e-308 < h

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{d \cdot c0}{D \cdot \left(w \cdot \sqrt{h}\right)} \cdot \frac{d \cdot c0}{D \cdot \left(w \cdot \sqrt{h}\right)}} \]
      4. unpow261.0%

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

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

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

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

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

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

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

    1. Initial program 0.0%

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

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

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

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

        \[\leadsto c0 \cdot \frac{-\left(c0 \cdot \color{blue}{\left(-\frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)} + c0 \cdot \frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)}{2 \cdot w} \]
      4. distribute-rgt-neg-in0.3%

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

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

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

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

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

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

        \[\leadsto c0 \cdot \frac{-\color{blue}{0}}{2 \cdot w} \]
      11. metadata-eval40.2%

        \[\leadsto c0 \cdot \frac{\color{blue}{0}}{2 \cdot w} \]
    6. Simplified40.2%

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

Alternative 3: 44.8% accurate, 1.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c0 \leq -4.4 \cdot 10^{-154} \lor \neg \left(c0 \leq 5.5 \cdot 10^{+49}\right):\\
\;\;\;\;\left(c0 \cdot 2\right) \cdot \left(\left({\left(\frac{d}{D}\right)}^{2} \cdot \frac{\frac{c0}{w}}{h}\right) \cdot \frac{0.5}{w}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c0 < -4.40000000000000015e-154 or 5.50000000000000042e49 < c0

    1. Initial program 30.9%

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

      \[\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 w around 0 7.4%

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

      \[\leadsto c0 \cdot \frac{\color{blue}{\frac{\mathsf{fma}\left(0.5, {D}^{2} \cdot \left(\frac{h}{c0} \cdot \frac{w \cdot 0}{{d}^{2}}\right), 2 \cdot \left(c0 \cdot \frac{{d}^{2}}{{D}^{2} \cdot h}\right)\right)}{w}}}{2 \cdot w} \]
    6. Taylor expanded in D around 0 42.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} \]
    7. Step-by-step derivation
      1. associate-/l*41.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -4.40000000000000015e-154 < c0 < 5.50000000000000042e49

    1. Initial program 18.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. Simplified33.6%

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

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

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

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

        \[\leadsto c0 \cdot \frac{-\left(c0 \cdot \color{blue}{\left(-\frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)} + c0 \cdot \frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)}{2 \cdot w} \]
      4. distribute-rgt-neg-in2.8%

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

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

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

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

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

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

        \[\leadsto c0 \cdot \frac{-\color{blue}{0}}{2 \cdot w} \]
      11. metadata-eval48.2%

        \[\leadsto c0 \cdot \frac{\color{blue}{0}}{2 \cdot w} \]
    6. Simplified48.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c0 \leq -4.4 \cdot 10^{-154} \lor \neg \left(c0 \leq 5.5 \cdot 10^{+49}\right):\\ \;\;\;\;\left(c0 \cdot 2\right) \cdot \left(\left({\left(\frac{d}{D}\right)}^{2} \cdot \frac{\frac{c0}{w}}{h}\right) \cdot \frac{0.5}{w}\right)\\ \mathbf{else}:\\ \;\;\;\;c0 \cdot \frac{0}{2 \cdot w}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 44.7% accurate, 1.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c0 \leq -2 \cdot 10^{-159} \lor \neg \left(c0 \leq 2.9 \cdot 10^{+49}\right):\\
\;\;\;\;c0 \cdot \frac{{\left(\frac{d}{D}\right)}^{2} \cdot \frac{\frac{c0}{w}}{h}}{w}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c0 < -1.99999999999999998e-159 or 2.9e49 < c0

    1. Initial program 30.9%

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

      \[\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 w around 0 7.4%

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

      \[\leadsto c0 \cdot \frac{\color{blue}{\frac{\mathsf{fma}\left(0.5, {D}^{2} \cdot \left(\frac{h}{c0} \cdot \frac{w \cdot 0}{{d}^{2}}\right), 2 \cdot \left(c0 \cdot \frac{{d}^{2}}{{D}^{2} \cdot h}\right)\right)}{w}}}{2 \cdot w} \]
    6. Taylor expanded in D around 0 42.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} \]
    7. Step-by-step derivation
      1. associate-/l*41.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.99999999999999998e-159 < c0 < 2.9e49

    1. Initial program 18.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. Simplified33.6%

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

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

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

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

        \[\leadsto c0 \cdot \frac{-\left(c0 \cdot \color{blue}{\left(-\frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)} + c0 \cdot \frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)}{2 \cdot w} \]
      4. distribute-rgt-neg-in2.8%

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

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

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

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

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

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

        \[\leadsto c0 \cdot \frac{-\color{blue}{0}}{2 \cdot w} \]
      11. metadata-eval48.2%

        \[\leadsto c0 \cdot \frac{\color{blue}{0}}{2 \cdot w} \]
    6. Simplified48.2%

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

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

Alternative 5: 43.9% accurate, 1.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c0 \leq -8 \cdot 10^{-158} \lor \neg \left(c0 \leq 3.4 \cdot 10^{+49}\right):\\
\;\;\;\;c0 \cdot \frac{{\left(\frac{d}{D}\right)}^{2} \cdot \frac{c0}{h \cdot w}}{w}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c0 < -8.00000000000000052e-158 or 3.4000000000000001e49 < c0

    1. Initial program 30.9%

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

      \[\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 w around 0 7.4%

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

      \[\leadsto c0 \cdot \frac{\color{blue}{\frac{\mathsf{fma}\left(0.5, {D}^{2} \cdot \left(\frac{h}{c0} \cdot \frac{w \cdot 0}{{d}^{2}}\right), 2 \cdot \left(c0 \cdot \frac{{d}^{2}}{{D}^{2} \cdot h}\right)\right)}{w}}}{2 \cdot w} \]
    6. Taylor expanded in D around 0 42.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} \]
    7. Step-by-step derivation
      1. associate-/l*41.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -8.00000000000000052e-158 < c0 < 3.4000000000000001e49

    1. Initial program 18.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. Simplified33.6%

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

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

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

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

        \[\leadsto c0 \cdot \frac{-\left(c0 \cdot \color{blue}{\left(-\frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)} + c0 \cdot \frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)}{2 \cdot w} \]
      4. distribute-rgt-neg-in2.8%

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

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

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

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

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

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

        \[\leadsto c0 \cdot \frac{-\color{blue}{0}}{2 \cdot w} \]
      11. metadata-eval48.2%

        \[\leadsto c0 \cdot \frac{\color{blue}{0}}{2 \cdot w} \]
    6. Simplified48.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c0 \leq -8 \cdot 10^{-158} \lor \neg \left(c0 \leq 3.4 \cdot 10^{+49}\right):\\ \;\;\;\;c0 \cdot \frac{{\left(\frac{d}{D}\right)}^{2} \cdot \frac{c0}{h \cdot w}}{w}\\ \mathbf{else}:\\ \;\;\;\;c0 \cdot \frac{0}{2 \cdot w}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 44.2% accurate, 1.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c0 \leq -7.2 \cdot 10^{-155} \lor \neg \left(c0 \leq 2.9 \cdot 10^{-21}\right):\\
\;\;\;\;c0 \cdot \left({\left(\frac{d}{D}\right)}^{2} \cdot \frac{\frac{c0}{h \cdot w}}{w}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c0 < -7.19999999999999977e-155 or 2.9e-21 < c0

    1. Initial program 29.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. Simplified44.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 w around 0 7.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -7.19999999999999977e-155 < c0 < 2.9e-21

    1. Initial program 19.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. Simplified33.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 3.5%

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

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

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

        \[\leadsto c0 \cdot \frac{-\left(c0 \cdot \color{blue}{\left(-\frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)} + c0 \cdot \frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)}{2 \cdot w} \]
      4. distribute-rgt-neg-in3.5%

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

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

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

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

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

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

        \[\leadsto c0 \cdot \frac{-\color{blue}{0}}{2 \cdot w} \]
      11. metadata-eval49.6%

        \[\leadsto c0 \cdot \frac{\color{blue}{0}}{2 \cdot w} \]
    6. Simplified49.6%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c0 \leq -7.2 \cdot 10^{-155} \lor \neg \left(c0 \leq 2.9 \cdot 10^{-21}\right):\\ \;\;\;\;c0 \cdot \left({\left(\frac{d}{D}\right)}^{2} \cdot \frac{\frac{c0}{h \cdot w}}{w}\right)\\ \mathbf{else}:\\ \;\;\;\;c0 \cdot \frac{0}{2 \cdot w}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 42.6% accurate, 1.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c0 \leq -2 \cdot 10^{-158} \lor \neg \left(c0 \leq 2.4 \cdot 10^{-21}\right):\\
\;\;\;\;c0 \cdot \left({\left(\frac{d}{D}\right)}^{2} \cdot \frac{c0}{w \cdot \left(h \cdot w\right)}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c0 < -2.00000000000000013e-158 or 2.3999999999999999e-21 < c0

    1. Initial program 29.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. Simplified44.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 w around 0 7.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.00000000000000013e-158 < c0 < 2.3999999999999999e-21

    1. Initial program 19.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. Simplified33.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 3.5%

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

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

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

        \[\leadsto c0 \cdot \frac{-\left(c0 \cdot \color{blue}{\left(-\frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)} + c0 \cdot \frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)}{2 \cdot w} \]
      4. distribute-rgt-neg-in3.5%

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

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

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

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

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

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

        \[\leadsto c0 \cdot \frac{-\color{blue}{0}}{2 \cdot w} \]
      11. metadata-eval49.6%

        \[\leadsto c0 \cdot \frac{\color{blue}{0}}{2 \cdot w} \]
    6. Simplified49.6%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c0 \leq -2 \cdot 10^{-158} \lor \neg \left(c0 \leq 2.4 \cdot 10^{-21}\right):\\ \;\;\;\;c0 \cdot \left({\left(\frac{d}{D}\right)}^{2} \cdot \frac{c0}{w \cdot \left(h \cdot w\right)}\right)\\ \mathbf{else}:\\ \;\;\;\;c0 \cdot \frac{0}{2 \cdot w}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 34.3% accurate, 21.6× speedup?

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

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

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

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

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

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

      \[\leadsto c0 \cdot \frac{-\left(c0 \cdot \color{blue}{\left(-\frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)} + c0 \cdot \frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)}{2 \cdot w} \]
    4. distribute-rgt-neg-in2.1%

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

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

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

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

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

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

      \[\leadsto c0 \cdot \frac{-\color{blue}{0}}{2 \cdot w} \]
    11. metadata-eval29.7%

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

    \[\leadsto c0 \cdot \frac{\color{blue}{0}}{2 \cdot w} \]
  7. Add Preprocessing

Reproduce

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