Henrywood and Agarwal, Equation (13)

Percentage Accurate: 25.3% → 54.5%
Time: 36.6s
Alternatives: 7
Speedup: 12.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 7 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: 25.3% accurate, 1.0× speedup?

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

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

Alternative 1: 54.5% accurate, 0.4× speedup?

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

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

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


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

    1. Initial program 71.9%

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

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

    1. Initial program 0.0%

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

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

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

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

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

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(c0 \cdot \color{blue}{\left(d \cdot \frac{d}{D \cdot \left(w \cdot \left(h \cdot D\right)\right)}\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) \]
      6. *-commutative0.0%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \mathsf{fma}\left(0.5, \frac{{D}^{2} \cdot \left(\color{blue}{\left(h \cdot w\right)} \cdot \frac{{M}^{2}}{{d}^{2}}\right)}{c0}, -1 \cdot \left(c0 \cdot \left(-1 \cdot \frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)} + \frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)\right)\right) \]
      9. associate-*r*2.9%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \mathsf{fma}\left(0.5, \frac{{D}^{2} \cdot \left(\left(h \cdot w\right) \cdot \frac{{M}^{2}}{{d}^{2}}\right)}{c0}, \color{blue}{\left(-1 \cdot c0\right) \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) \]
    7. Simplified22.4%

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 46.9% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
t_0 := c0 \cdot \frac{0}{2 \cdot w}\\
t_1 := {\left(\frac{d}{D}\right)}^{2}\\
t_2 := c0 \cdot \frac{\frac{t\_1}{h} \cdot \frac{c0}{w}}{w}\\
\mathbf{if}\;c0 \leq -3.8 \cdot 10^{-180}:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;c0 \leq 1.85 \cdot 10^{-128}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;c0 \leq 1.05 \cdot 10^{+74}:\\
\;\;\;\;c0 \cdot \frac{2 \cdot \left(c0 \cdot \frac{t\_1}{w \cdot h}\right)}{2 \cdot w}\\

\mathbf{elif}\;c0 \leq 1.85 \cdot 10^{+124}:\\
\;\;\;\;t\_0\\

\mathbf{else}:\\
\;\;\;\;t\_2\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c0 < -3.79999999999999999e-180 or 1.85000000000000004e124 < c0

    1. Initial program 22.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. Simplified38.4%

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

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

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

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

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

        \[\leadsto c0 \cdot \frac{2 \cdot \frac{\frac{\color{blue}{\frac{c0}{w} \cdot {d}^{2}}}{h}}{{D}^{2}}}{2 \cdot w} \]
      5. associate-/r*39.1%

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

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

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

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

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

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

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

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

        \[\leadsto c0 \cdot \left(1 \cdot \frac{\frac{c0}{w} \cdot \frac{\frac{d \cdot d}{\color{blue}{D \cdot D}}}{h}}{w}\right) \]
      6. frac-times48.9%

        \[\leadsto c0 \cdot \left(1 \cdot \frac{\frac{c0}{w} \cdot \frac{\color{blue}{\frac{d}{D} \cdot \frac{d}{D}}}{h}}{w}\right) \]
      7. pow248.9%

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

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

    if -3.79999999999999999e-180 < c0 < 1.85e-128 or 1.0499999999999999e74 < c0 < 1.85000000000000004e124

    1. Initial program 14.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. Simplified22.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 4.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. associate-*r*4.0%

        \[\leadsto c0 \cdot \frac{\color{blue}{\left(-1 \cdot c0\right) \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. neg-mul-14.0%

        \[\leadsto c0 \cdot \frac{\color{blue}{\left(-c0\right)} \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} \]
      3. distribute-lft1-in4.0%

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

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

        \[\leadsto c0 \cdot \frac{\left(-c0\right) \cdot \color{blue}{0}}{2 \cdot w} \]
      6. distribute-lft-neg-in51.4%

        \[\leadsto c0 \cdot \frac{\color{blue}{-c0 \cdot 0}}{2 \cdot w} \]
      7. distribute-rgt-neg-in51.4%

        \[\leadsto c0 \cdot \frac{\color{blue}{c0 \cdot \left(-0\right)}}{2 \cdot w} \]
      8. metadata-eval51.4%

        \[\leadsto c0 \cdot \frac{c0 \cdot \color{blue}{0}}{2 \cdot w} \]
      9. mul0-lft4.0%

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

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

        \[\leadsto c0 \cdot \frac{c0 \cdot \color{blue}{\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} \]
      12. distribute-lft-in4.0%

        \[\leadsto c0 \cdot \frac{\color{blue}{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)}}}{2 \cdot w} \]
      13. associate-/l*3.9%

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

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

    if 1.85e-128 < c0 < 1.0499999999999999e74

    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. Simplified53.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. Applied egg-rr61.7%

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

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

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

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

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

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

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

        \[\leadsto c0 \cdot \frac{2 \cdot \frac{\color{blue}{c0 \cdot \frac{{d}^{2}}{{D}^{2}}}}{h \cdot w}}{2 \cdot w} \]
      3. unpow251.6%

        \[\leadsto c0 \cdot \frac{2 \cdot \frac{c0 \cdot \frac{\color{blue}{d \cdot d}}{{D}^{2}}}{h \cdot w}}{2 \cdot w} \]
      4. unpow251.6%

        \[\leadsto c0 \cdot \frac{2 \cdot \frac{c0 \cdot \frac{d \cdot d}{\color{blue}{D \cdot D}}}{h \cdot w}}{2 \cdot w} \]
      5. times-frac61.7%

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

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

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

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

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

      \[\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} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification51.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;c0 \leq -3.8 \cdot 10^{-180}:\\ \;\;\;\;c0 \cdot \frac{\frac{{\left(\frac{d}{D}\right)}^{2}}{h} \cdot \frac{c0}{w}}{w}\\ \mathbf{elif}\;c0 \leq 1.85 \cdot 10^{-128}:\\ \;\;\;\;c0 \cdot \frac{0}{2 \cdot w}\\ \mathbf{elif}\;c0 \leq 1.05 \cdot 10^{+74}:\\ \;\;\;\;c0 \cdot \frac{2 \cdot \left(c0 \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{w \cdot h}\right)}{2 \cdot w}\\ \mathbf{elif}\;c0 \leq 1.85 \cdot 10^{+124}:\\ \;\;\;\;c0 \cdot \frac{0}{2 \cdot w}\\ \mathbf{else}:\\ \;\;\;\;c0 \cdot \frac{\frac{{\left(\frac{d}{D}\right)}^{2}}{h} \cdot \frac{c0}{w}}{w}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 45.0% accurate, 1.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;M \cdot M \leq 2 \cdot 10^{-244}:\\
\;\;\;\;c0 \cdot \frac{0}{2 \cdot w}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 M M) < 1.9999999999999999e-244

    1. Initial program 28.8%

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

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

      \[\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. associate-*r*12.4%

        \[\leadsto c0 \cdot \frac{\color{blue}{\left(-1 \cdot c0\right) \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. neg-mul-112.4%

        \[\leadsto c0 \cdot \frac{\color{blue}{\left(-c0\right)} \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} \]
      3. distribute-lft1-in12.4%

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

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

        \[\leadsto c0 \cdot \frac{\left(-c0\right) \cdot \color{blue}{0}}{2 \cdot w} \]
      6. distribute-lft-neg-in45.2%

        \[\leadsto c0 \cdot \frac{\color{blue}{-c0 \cdot 0}}{2 \cdot w} \]
      7. distribute-rgt-neg-in45.2%

        \[\leadsto c0 \cdot \frac{\color{blue}{c0 \cdot \left(-0\right)}}{2 \cdot w} \]
      8. metadata-eval45.2%

        \[\leadsto c0 \cdot \frac{c0 \cdot \color{blue}{0}}{2 \cdot w} \]
      9. mul0-lft12.4%

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

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

        \[\leadsto c0 \cdot \frac{c0 \cdot \color{blue}{\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} \]
      12. distribute-lft-in12.4%

        \[\leadsto c0 \cdot \frac{\color{blue}{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)}}}{2 \cdot w} \]
      13. associate-/l*8.1%

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

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

    if 1.9999999999999999e-244 < (*.f64 M M)

    1. Initial program 18.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. Simplified41.3%

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

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

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

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

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

        \[\leadsto c0 \cdot \frac{2 \cdot \frac{\frac{\color{blue}{\frac{c0}{w} \cdot {d}^{2}}}{h}}{{D}^{2}}}{2 \cdot w} \]
      5. associate-/r*41.6%

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

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

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

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

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

        \[\leadsto c0 \cdot \frac{2 \cdot \frac{c0 \cdot \color{blue}{\frac{\frac{{d}^{2}}{{D}^{2}}}{h}}}{w}}{2 \cdot w} \]
      3. pow240.0%

        \[\leadsto c0 \cdot \frac{2 \cdot \frac{c0 \cdot \frac{\frac{\color{blue}{d \cdot d}}{{D}^{2}}}{h}}{w}}{2 \cdot w} \]
      4. pow240.0%

        \[\leadsto c0 \cdot \frac{2 \cdot \frac{c0 \cdot \frac{\frac{d \cdot d}{\color{blue}{D \cdot D}}}{h}}{w}}{2 \cdot w} \]
      5. frac-times50.0%

        \[\leadsto c0 \cdot \frac{2 \cdot \frac{c0 \cdot \frac{\color{blue}{\frac{d}{D} \cdot \frac{d}{D}}}{h}}{w}}{2 \cdot w} \]
      6. pow250.0%

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

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

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

Alternative 4: 48.7% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c0 \leq -2.7 \cdot 10^{-177} \lor \neg \left(c0 \leq 2.3 \cdot 10^{-125}\right):\\ \;\;\;\;c0 \cdot \frac{\frac{{\left(\frac{d}{D}\right)}^{2}}{h} \cdot \frac{c0}{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 -2.7e-177) (not (<= c0 2.3e-125)))
   (* c0 (/ (* (/ (pow (/ d D) 2.0) h) (/ c0 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 <= -2.7e-177) || !(c0 <= 2.3e-125)) {
		tmp = c0 * (((pow((d / D), 2.0) / h) * (c0 / 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 <= (-2.7d-177)) .or. (.not. (c0 <= 2.3d-125))) then
        tmp = c0 * (((((d_1 / d) ** 2.0d0) / h) * (c0 / 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 <= -2.7e-177) || !(c0 <= 2.3e-125)) {
		tmp = c0 * (((Math.pow((d / D), 2.0) / h) * (c0 / w)) / w);
	} else {
		tmp = c0 * (0.0 / (2.0 * w));
	}
	return tmp;
}
def code(c0, w, h, D, d, M):
	tmp = 0
	if (c0 <= -2.7e-177) or not (c0 <= 2.3e-125):
		tmp = c0 * (((math.pow((d / D), 2.0) / h) * (c0 / 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 <= -2.7e-177) || !(c0 <= 2.3e-125))
		tmp = Float64(c0 * Float64(Float64(Float64((Float64(d / D) ^ 2.0) / h) * Float64(c0 / 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 <= -2.7e-177) || ~((c0 <= 2.3e-125)))
		tmp = c0 * (((((d / D) ^ 2.0) / h) * (c0 / 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, -2.7e-177], N[Not[LessEqual[c0, 2.3e-125]], $MachinePrecision]], N[(c0 * N[(N[(N[(N[Power[N[(d / D), $MachinePrecision], 2.0], $MachinePrecision] / h), $MachinePrecision] * N[(c0 / w), $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.7 \cdot 10^{-177} \lor \neg \left(c0 \leq 2.3 \cdot 10^{-125}\right):\\
\;\;\;\;c0 \cdot \frac{\frac{{\left(\frac{d}{D}\right)}^{2}}{h} \cdot \frac{c0}{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 < -2.7000000000000002e-177 or 2.2999999999999999e-125 < c0

    1. Initial program 23.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. Simplified40.4%

      \[\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 37.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} \]
    5. Step-by-step derivation
      1. *-commutative37.6%

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

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

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

        \[\leadsto c0 \cdot \frac{2 \cdot \frac{\frac{\color{blue}{\frac{c0}{w} \cdot {d}^{2}}}{h}}{{D}^{2}}}{2 \cdot w} \]
      5. associate-/r*39.5%

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.7000000000000002e-177 < c0 < 2.2999999999999999e-125

    1. Initial program 13.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. 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 2.6%

      \[\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. associate-*r*2.6%

        \[\leadsto c0 \cdot \frac{\color{blue}{\left(-1 \cdot c0\right) \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. neg-mul-12.6%

        \[\leadsto c0 \cdot \frac{\color{blue}{\left(-c0\right)} \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} \]
      3. distribute-lft1-in2.6%

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

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

        \[\leadsto c0 \cdot \frac{\left(-c0\right) \cdot \color{blue}{0}}{2 \cdot w} \]
      6. distribute-lft-neg-in50.4%

        \[\leadsto c0 \cdot \frac{\color{blue}{-c0 \cdot 0}}{2 \cdot w} \]
      7. distribute-rgt-neg-in50.4%

        \[\leadsto c0 \cdot \frac{\color{blue}{c0 \cdot \left(-0\right)}}{2 \cdot w} \]
      8. metadata-eval50.4%

        \[\leadsto c0 \cdot \frac{c0 \cdot \color{blue}{0}}{2 \cdot w} \]
      9. mul0-lft2.6%

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

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

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

        \[\leadsto c0 \cdot \frac{\color{blue}{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)}}}{2 \cdot w} \]
      13. associate-/l*2.6%

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

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

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

Alternative 5: 29.5% accurate, 12.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;M \leq 3.05 \cdot 10^{+91}:\\
\;\;\;\;c0 \cdot \frac{0}{2 \cdot w}\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(M \cdot \frac{c0}{w}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if M < 3.05e91

    1. Initial program 23.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. Simplified39.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 5.4%

      \[\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. associate-*r*5.4%

        \[\leadsto c0 \cdot \frac{\color{blue}{\left(-1 \cdot c0\right) \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. neg-mul-15.4%

        \[\leadsto c0 \cdot \frac{\color{blue}{\left(-c0\right)} \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} \]
      3. distribute-lft1-in5.4%

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

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

        \[\leadsto c0 \cdot \frac{\left(-c0\right) \cdot \color{blue}{0}}{2 \cdot w} \]
      6. distribute-lft-neg-in29.0%

        \[\leadsto c0 \cdot \frac{\color{blue}{-c0 \cdot 0}}{2 \cdot w} \]
      7. distribute-rgt-neg-in29.0%

        \[\leadsto c0 \cdot \frac{\color{blue}{c0 \cdot \left(-0\right)}}{2 \cdot w} \]
      8. metadata-eval29.0%

        \[\leadsto c0 \cdot \frac{c0 \cdot \color{blue}{0}}{2 \cdot w} \]
      9. mul0-lft5.4%

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

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

        \[\leadsto c0 \cdot \frac{c0 \cdot \color{blue}{\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} \]
      12. distribute-lft-in5.4%

        \[\leadsto c0 \cdot \frac{\color{blue}{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)}}}{2 \cdot w} \]
      13. associate-/l*4.0%

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

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

    if 3.05e91 < M

    1. Initial program 10.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. Simplified31.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. Applied egg-rr48.6%

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

      \[\leadsto \color{blue}{0.5 \cdot \frac{M \cdot c0}{w}} \]
    6. Step-by-step derivation
      1. associate-/l*25.5%

        \[\leadsto 0.5 \cdot \color{blue}{\left(M \cdot \frac{c0}{w}\right)} \]
    7. Simplified25.5%

      \[\leadsto \color{blue}{0.5 \cdot \left(M \cdot \frac{c0}{w}\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification28.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;M \leq 3.05 \cdot 10^{+91}:\\ \;\;\;\;c0 \cdot \frac{0}{2 \cdot w}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(M \cdot \frac{c0}{w}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 29.7% accurate, 12.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;M \leq 2.1 \cdot 10^{+91}:\\
\;\;\;\;c0 \cdot \frac{0}{2 \cdot w}\\

\mathbf{else}:\\
\;\;\;\;c0 \cdot \frac{M \cdot 0.5}{w}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if M < 2.10000000000000008e91

    1. Initial program 23.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. Simplified39.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 5.4%

      \[\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. associate-*r*5.4%

        \[\leadsto c0 \cdot \frac{\color{blue}{\left(-1 \cdot c0\right) \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. neg-mul-15.4%

        \[\leadsto c0 \cdot \frac{\color{blue}{\left(-c0\right)} \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} \]
      3. distribute-lft1-in5.4%

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

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

        \[\leadsto c0 \cdot \frac{\left(-c0\right) \cdot \color{blue}{0}}{2 \cdot w} \]
      6. distribute-lft-neg-in29.0%

        \[\leadsto c0 \cdot \frac{\color{blue}{-c0 \cdot 0}}{2 \cdot w} \]
      7. distribute-rgt-neg-in29.0%

        \[\leadsto c0 \cdot \frac{\color{blue}{c0 \cdot \left(-0\right)}}{2 \cdot w} \]
      8. metadata-eval29.0%

        \[\leadsto c0 \cdot \frac{c0 \cdot \color{blue}{0}}{2 \cdot w} \]
      9. mul0-lft5.4%

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

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

        \[\leadsto c0 \cdot \frac{c0 \cdot \color{blue}{\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} \]
      12. distribute-lft-in5.4%

        \[\leadsto c0 \cdot \frac{\color{blue}{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)}}}{2 \cdot w} \]
      13. associate-/l*4.0%

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

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

    if 2.10000000000000008e91 < M

    1. Initial program 10.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. Simplified31.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. Applied egg-rr48.6%

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

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

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

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

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

      \[\leadsto c0 \cdot \color{blue}{\left(0.5 \cdot \frac{M}{w}\right)} \]
    8. Step-by-step derivation
      1. associate-*r/27.7%

        \[\leadsto c0 \cdot \color{blue}{\frac{0.5 \cdot M}{w}} \]
    9. Simplified27.7%

      \[\leadsto c0 \cdot \color{blue}{\frac{0.5 \cdot M}{w}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification28.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;M \leq 2.1 \cdot 10^{+91}:\\ \;\;\;\;c0 \cdot \frac{0}{2 \cdot w}\\ \mathbf{else}:\\ \;\;\;\;c0 \cdot \frac{M \cdot 0.5}{w}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 19.2% accurate, 21.6× speedup?

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

\\
0.5 \cdot \left(M \cdot \frac{c0}{w}\right)
\end{array}
Derivation
  1. Initial program 21.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. 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. Applied egg-rr43.9%

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

    \[\leadsto \color{blue}{0.5 \cdot \frac{M \cdot c0}{w}} \]
  6. Step-by-step derivation
    1. associate-/l*16.8%

      \[\leadsto 0.5 \cdot \color{blue}{\left(M \cdot \frac{c0}{w}\right)} \]
  7. Simplified16.8%

    \[\leadsto \color{blue}{0.5 \cdot \left(M \cdot \frac{c0}{w}\right)} \]
  8. Final simplification16.8%

    \[\leadsto 0.5 \cdot \left(M \cdot \frac{c0}{w}\right) \]
  9. Add Preprocessing

Reproduce

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