Henrywood and Agarwal, Equation (13)

Percentage Accurate: 25.3% → 54.5%
Time: 30.2s
Alternatives: 5
Speedup: 21.6×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 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: 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.2× speedup?

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

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

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


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

    1. Initial program 69.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. Simplified66.5%

      \[\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. Applied egg-rr68.2%

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

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

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

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

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \mathsf{fma}\left(\frac{d}{D} \cdot \sqrt{\frac{\frac{c0}{w}}{h}}, \color{blue}{-0.5 \cdot \left(\frac{D \cdot M}{d} \cdot \sqrt{\frac{h \cdot w}{c0}}\right) + \frac{d}{D} \cdot \sqrt{\frac{c0}{h \cdot w}}}, \frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2}\right) \]
    9. Step-by-step derivation
      1. add-sqr-sqrt68.2%

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

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

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

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

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \mathsf{fma}\left(\frac{d}{D} \cdot \sqrt{\frac{\frac{c0}{w}}{h}}, -0.5 \cdot \left(\frac{D \cdot M}{d} \cdot \sqrt{\frac{h \cdot w}{c0}}\right) + \frac{d}{D} \cdot \sqrt{\frac{c0}{h \cdot w}}, {\left(\color{blue}{{\left(\frac{d}{D}\right)}^{\left(\frac{2}{2}\right)}} \cdot \sqrt{\frac{c0}{w \cdot h}}\right)}^{2}\right) \]
      6. metadata-eval74.3%

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

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

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \mathsf{fma}\left(\frac{d}{D} \cdot \sqrt{\frac{\frac{c0}{w}}{h}}, -0.5 \cdot \left(\frac{D \cdot M}{d} \cdot \sqrt{\frac{h \cdot w}{c0}}\right) + \frac{d}{D} \cdot \sqrt{\frac{c0}{h \cdot w}}, {\left(\frac{d}{D} \cdot \sqrt{\color{blue}{\frac{\frac{c0}{w}}{h}}}\right)}^{2}\right) \]
    10. Applied egg-rr74.3%

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

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

      \[\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. distribute-lft-in0.8%

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

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

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

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

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

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

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

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

        \[\leadsto c0 \cdot \frac{-1 \cdot \color{blue}{0}}{2 \cdot w} \]
      10. metadata-eval37.7%

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

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

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

Alternative 2: 38.0% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;M \leq 1.8 \cdot 10^{-111}:\\ \;\;\;\;c0 \cdot \frac{0}{2 \cdot w}\\ \mathbf{else}:\\ \;\;\;\;c0 \cdot \frac{\mathsf{fma}\left(c0, d \cdot \frac{d}{D \cdot \left(h \cdot \left(w \cdot D\right)\right)}, \frac{d}{D} \cdot \left(\frac{d}{D} \cdot \frac{c0}{w \cdot h}\right)\right)}{2 \cdot w}\\ \end{array} \end{array} \]
(FPCore (c0 w h D d M)
 :precision binary64
 (if (<= M 1.8e-111)
   (* c0 (/ 0.0 (* 2.0 w)))
   (*
    c0
    (/
     (fma
      c0
      (* d (/ d (* D (* h (* w D)))))
      (* (/ d D) (* (/ d D) (/ c0 (* w h)))))
     (* 2.0 w)))))
double code(double c0, double w, double h, double D, double d, double M) {
	double tmp;
	if (M <= 1.8e-111) {
		tmp = c0 * (0.0 / (2.0 * w));
	} else {
		tmp = c0 * (fma(c0, (d * (d / (D * (h * (w * D))))), ((d / D) * ((d / D) * (c0 / (w * h))))) / (2.0 * w));
	}
	return tmp;
}
function code(c0, w, h, D, d, M)
	tmp = 0.0
	if (M <= 1.8e-111)
		tmp = Float64(c0 * Float64(0.0 / Float64(2.0 * w)));
	else
		tmp = Float64(c0 * Float64(fma(c0, Float64(d * Float64(d / Float64(D * Float64(h * Float64(w * D))))), Float64(Float64(d / D) * Float64(Float64(d / D) * Float64(c0 / Float64(w * h))))) / Float64(2.0 * w)));
	end
	return tmp
end
code[c0_, w_, h_, D_, d_, M_] := If[LessEqual[M, 1.8e-111], N[(c0 * N[(0.0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(c0 * N[(N[(c0 * N[(d * N[(d / N[(D * N[(h * N[(w * D), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(d / D), $MachinePrecision] * N[(N[(d / D), $MachinePrecision] * N[(c0 / N[(w * h), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(2.0 * w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

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

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


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

    1. Initial program 24.3%

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

      \[\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. distribute-lft-in5.2%

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

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

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

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

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

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

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

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

        \[\leadsto c0 \cdot \frac{-1 \cdot \color{blue}{0}}{2 \cdot w} \]
      10. metadata-eval36.7%

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

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

    if 1.80000000000000005e-111 < M

    1. Initial program 12.1%

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

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

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

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

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

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

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

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

        \[\leadsto c0 \cdot \frac{\mathsf{fma}\left(c0, d \cdot \frac{d}{D \cdot \left(w \cdot \left(h \cdot D\right)\right)}, \color{blue}{\left(\frac{c0}{w \cdot h} \cdot \frac{d}{D}\right) \cdot \frac{d}{D}}\right)}{2 \cdot w} \]
    6. Applied egg-rr45.3%

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

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

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

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

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

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

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

Alternative 3: 37.9% accurate, 1.2× speedup?

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

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

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


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

    1. Initial program 23.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. Simplified40.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 6.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. distribute-lft-in5.9%

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

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

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

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

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

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

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

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

        \[\leadsto c0 \cdot \frac{-1 \cdot \color{blue}{0}}{2 \cdot w} \]
      10. metadata-eval33.3%

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

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

    if 7.80000000000000008e-258 < M

    1. Initial program 18.3%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\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. *-commutative30.3%

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

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

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

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

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

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

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

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

Alternative 4: 38.3% accurate, 1.2× speedup?

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

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

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


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

    1. Initial program 24.3%

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

      \[\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. distribute-lft-in5.2%

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

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

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

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

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

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

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

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

        \[\leadsto c0 \cdot \frac{-1 \cdot \color{blue}{0}}{2 \cdot w} \]
      10. metadata-eval36.7%

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

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

    if 7.3999999999999996e-112 < M

    1. Initial program 12.1%

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

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

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

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

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

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

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

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

        \[\leadsto c0 \cdot \frac{\mathsf{fma}\left(c0, d \cdot \frac{d}{D \cdot \left(w \cdot \left(h \cdot D\right)\right)}, \color{blue}{\left(\frac{c0}{w \cdot h} \cdot \frac{d}{D}\right) \cdot \frac{d}{D}}\right)}{2 \cdot w} \]
    6. Applied egg-rr45.3%

      \[\leadsto c0 \cdot \frac{\mathsf{fma}\left(c0, d \cdot \frac{d}{D \cdot \left(w \cdot \left(h \cdot D\right)\right)}, \color{blue}{\left(\frac{c0}{w \cdot h} \cdot \frac{d}{D}\right) \cdot \frac{d}{D}}\right)}{2 \cdot w} \]
    7. Taylor expanded in c0 around 0 31.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. *-commutative31.7%

        \[\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. *-commutative31.7%

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

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

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

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

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

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

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

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

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

Alternative 5: 32.8% accurate, 21.6× speedup?

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

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

    \[\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. distribute-lft-in3.9%

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

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

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

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

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

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

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

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

      \[\leadsto c0 \cdot \frac{-1 \cdot \color{blue}{0}}{2 \cdot w} \]
    10. metadata-eval30.7%

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

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

Reproduce

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