Henrywood and Agarwal, Equation (13)

Percentage Accurate: 24.5% → 53.4%
Time: 29.2s
Alternatives: 5
Speedup: 16.8×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 5 alternatives:

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

Initial Program: 24.5% accurate, 1.0× speedup?

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

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

Alternative 1: 53.4% accurate, 0.3× speedup?

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

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

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


\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 74.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. Simplified75.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto -0.25 \cdot {\left({\color{blue}{\left(\left({D}^{2} \cdot {M}^{2}\right) \cdot \frac{h}{{d}^{2}}\right)}}^{3}\right)}^{0.3333333333333333} \]
      5. unpow-prod-down45.5%

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

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

        \[\leadsto -0.25 \cdot {\left({\left({\left(D \cdot M\right)}^{2} \cdot \left(h \cdot \color{blue}{{d}^{\left(-2\right)}}\right)\right)}^{3}\right)}^{0.3333333333333333} \]
      8. metadata-eval45.5%

        \[\leadsto -0.25 \cdot {\left({\left({\left(D \cdot M\right)}^{2} \cdot \left(h \cdot {d}^{\color{blue}{-2}}\right)\right)}^{3}\right)}^{0.3333333333333333} \]
    9. Applied egg-rr45.5%

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

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

Alternative 2: 35.0% accurate, 0.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;M \leq 5.1 \cdot 10^{-182}:\\
\;\;\;\;c0 \cdot \log \left({\left(e^{M}\right)}^{\left(\frac{\sqrt{-1}}{2 \cdot w}\right)}\right)\\

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


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

    1. Initial program 25.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. Simplified34.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 \mathsf{fma}\left(\frac{c0}{w \cdot \left(h \cdot D\right)}, \frac{d \cdot d}{D}, -M\right)}\right)}{2 \cdot w}} \]
    3. Add Preprocessing
    4. Taylor expanded in c0 around 0 0.0%

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

        \[\leadsto c0 \cdot \color{blue}{\log \left(e^{\frac{M \cdot \sqrt{-1}}{2 \cdot w}}\right)} \]
      2. associate-/l*0.0%

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

        \[\leadsto c0 \cdot \log \color{blue}{\left({\left(e^{M}\right)}^{\left(\frac{\sqrt{-1}}{2 \cdot w}\right)}\right)} \]
      4. *-commutative33.8%

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

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

    if 5.10000000000000017e-182 < M

    1. Initial program 19.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 37.2% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;M \leq 5.7 \cdot 10^{-182}:\\
\;\;\;\;\frac{-0.25 \cdot \left(h \cdot {\left(D \cdot M\right)}^{2}\right)}{{d}^{2}}\\

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


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

    1. Initial program 25.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. Simplified26.2%

      \[\leadsto \color{blue}{\frac{c0}{2 \cdot w} \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D} + \sqrt{\left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\right) \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\right) - M \cdot M}\right)} \]
    3. Add Preprocessing
    4. Taylor expanded in M around 0 24.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}} + 2 \cdot \frac{c0 \cdot {d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)} \]
    5. Taylor expanded in c0 around 0 32.7%

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

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

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

      \[\leadsto \color{blue}{-0.25 \cdot \left({D}^{2} \cdot \left({M}^{2} \cdot \frac{h}{{d}^{2}}\right)\right)} \]
    8. Taylor expanded in D around 0 32.7%

      \[\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-*r/32.7%

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

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

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

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

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

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

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

    if 5.6999999999999998e-182 < M

    1. Initial program 19.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 36.1% accurate, 1.2× speedup?

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

\\
\begin{array}{l}
t_0 := \frac{c0}{2 \cdot w}\\
\mathbf{if}\;M \leq 5.3 \cdot 10^{-182}:\\
\;\;\;\;t\_0 \cdot \left(c0 \cdot 0\right)\\

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


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

    1. Initial program 25.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. Simplified26.2%

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

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

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

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

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

      \[\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)\right)} \]
    9. Step-by-step derivation
      1. associate-*r*6.7%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{\left(\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)} \]
      2. mul-1-neg6.7%

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(\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)\right) \]
      3. distribute-lft1-in6.7%

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

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

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

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

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

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(c0 \cdot \color{blue}{0}\right) \]
    10. Simplified36.6%

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{\left(c0 \cdot 0\right)} \]

    if 5.30000000000000005e-182 < M

    1. Initial program 19.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 29.6% accurate, 16.8× speedup?

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

\\
\frac{c0}{2 \cdot w} \cdot \left(c0 \cdot 0\right)
\end{array}
Derivation
  1. Initial program 23.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. Simplified24.2%

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

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

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

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

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

    \[\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)\right)} \]
  9. Step-by-step derivation
    1. associate-*r*4.9%

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{\left(\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)} \]
    2. mul-1-neg4.9%

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

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

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

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

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

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

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(c0 \cdot \color{blue}{0}\right) \]
  10. Simplified31.4%

    \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{\left(c0 \cdot 0\right)} \]
  11. Add Preprocessing

Reproduce

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