Henrywood and Agarwal, Equation (13)

Percentage Accurate: 25.1% → 43.8%
Time: 35.1s
Alternatives: 3
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 3 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.1% 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: 43.8% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c0 \leq -1.4 \cdot 10^{+265} \lor \neg \left(c0 \leq -1.35 \cdot 10^{+193} \lor \neg \left(c0 \leq -6.4 \cdot 10^{-169}\right) \land c0 \leq 3.1 \cdot 10^{+37}\right):\\
\;\;\;\;c0 \cdot \left({\left(\frac{d}{D}\right)}^{2} \cdot \frac{\frac{\frac{c0}{w}}{h}}{w}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c0 < -1.39999999999999995e265 or -1.35e193 < c0 < -6.39999999999999989e-169 or 3.1000000000000002e37 < c0

    1. Initial program 29.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. Simplified47.0%

      \[\leadsto \color{blue}{c0 \cdot \frac{\mathsf{fma}\left(c0, d \cdot \frac{d}{D \cdot \left(w \cdot \left(h \cdot D\right)\right)}, \sqrt{\mathsf{fma}\left(c0, d \cdot \frac{d}{D \cdot \left(w \cdot \left(h \cdot D\right)\right)}, M\right) \cdot \left(c0 \cdot \left(d \cdot \frac{d}{D \cdot \left(w \cdot \left(h \cdot D\right)\right)}\right) - M\right)}\right)}{2 \cdot w}} \]
    3. Add Preprocessing
    4. Taylor expanded in c0 around -inf 4.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}{-1 \cdot \frac{c0 \cdot {d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}}\right)}{2 \cdot w} \]
    5. Step-by-step derivation
      1. mul-1-neg4.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} \]
      2. associate-/l*5.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}{c0 \cdot \frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}}\right)}{2 \cdot w} \]
      3. distribute-rgt-neg-in5.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}{c0 \cdot \left(-\frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)}\right)}{2 \cdot w} \]
      4. *-commutative5.6%

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

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

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

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

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

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

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

        \[\leadsto c0 \cdot \frac{\mathsf{fma}\left(c0, d \cdot \frac{d}{D \cdot \left(w \cdot \left(h \cdot D\right)\right)}, c0 \cdot \frac{{d}^{2}}{{D}^{2} \cdot \color{blue}{\left(w \cdot \left(-h\right)\right)}}\right)}{2 \cdot w} \]
    6. Simplified5.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}{c0 \cdot \frac{{d}^{2}}{{D}^{2} \cdot \left(w \cdot \left(-h\right)\right)}}\right)}{2 \cdot w} \]
    7. Step-by-step derivation
      1. associate-*r/4.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(w \cdot \left(-h\right)\right)}}\right)}{2 \cdot w} \]
      2. *-commutative4.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 \left(-h\right)\right) \cdot {D}^{2}}}\right)}{2 \cdot w} \]
      3. times-frac4.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}{w \cdot \left(-h\right)} \cdot \frac{{d}^{2}}{{D}^{2}}}\right)}{2 \cdot w} \]
      4. add-sqr-sqrt2.0%

        \[\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 \color{blue}{\left(\sqrt{-h} \cdot \sqrt{-h}\right)}} \cdot \frac{{d}^{2}}{{D}^{2}}\right)}{2 \cdot w} \]
      5. sqrt-unprod17.0%

        \[\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 \color{blue}{\sqrt{\left(-h\right) \cdot \left(-h\right)}}} \cdot \frac{{d}^{2}}{{D}^{2}}\right)}{2 \cdot w} \]
      6. sqr-neg17.0%

        \[\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 \sqrt{\color{blue}{h \cdot h}}} \cdot \frac{{d}^{2}}{{D}^{2}}\right)}{2 \cdot w} \]
      7. sqrt-unprod20.5%

        \[\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 \color{blue}{\left(\sqrt{h} \cdot \sqrt{h}\right)}} \cdot \frac{{d}^{2}}{{D}^{2}}\right)}{2 \cdot w} \]
      8. add-sqr-sqrt36.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}{w \cdot \color{blue}{h}} \cdot \frac{{d}^{2}}{{D}^{2}}\right)}{2 \cdot w} \]
      9. *-commutative36.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}{\color{blue}{h \cdot w}} \cdot \frac{{d}^{2}}{{D}^{2}}\right)}{2 \cdot w} \]
      10. unpow236.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}{h \cdot w} \cdot \frac{\color{blue}{d \cdot d}}{{D}^{2}}\right)}{2 \cdot w} \]
      11. unpow236.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}{h \cdot w} \cdot \frac{d \cdot d}{\color{blue}{D \cdot D}}\right)}{2 \cdot w} \]
      12. frac-times44.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}{h \cdot w} \cdot \color{blue}{\left(\frac{d}{D} \cdot \frac{d}{D}\right)}\right)}{2 \cdot w} \]
      13. unpow244.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}{h \cdot w} \cdot \color{blue}{{\left(\frac{d}{D}\right)}^{2}}\right)}{2 \cdot w} \]
      14. add-sqr-sqrt42.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}{\sqrt{\frac{c0}{h \cdot w} \cdot {\left(\frac{d}{D}\right)}^{2}} \cdot \sqrt{\frac{c0}{h \cdot w} \cdot {\left(\frac{d}{D}\right)}^{2}}}\right)}{2 \cdot w} \]
      15. pow242.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}{{\left(\sqrt{\frac{c0}{h \cdot w} \cdot {\left(\frac{d}{D}\right)}^{2}}\right)}^{2}}\right)}{2 \cdot w} \]
    8. Applied egg-rr48.4%

      \[\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{d}{D} \cdot \sqrt{\frac{\frac{c0}{w}}{h}}\right)}^{2}}\right)}{2 \cdot w} \]
    9. Taylor expanded in h around -inf 0.0%

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

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

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

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

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

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

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

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

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

    if -1.39999999999999995e265 < c0 < -1.35e193 or -6.39999999999999989e-169 < c0 < 3.1000000000000002e37

    1. Initial program 8.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. Simplified15.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 1.1%

      \[\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-in1.1%

        \[\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-neg1.1%

        \[\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-in1.1%

        \[\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.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-neg0.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*2.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-in2.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-eval2.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-lft52.6%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c0 \leq -1.4 \cdot 10^{+265} \lor \neg \left(c0 \leq -1.35 \cdot 10^{+193} \lor \neg \left(c0 \leq -6.4 \cdot 10^{-169}\right) \land c0 \leq 3.1 \cdot 10^{+37}\right):\\ \;\;\;\;c0 \cdot \left({\left(\frac{d}{D}\right)}^{2} \cdot \frac{\frac{\frac{c0}{w}}{h}}{w}\right)\\ \mathbf{else}:\\ \;\;\;\;c0 \cdot \frac{0}{2 \cdot w}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 54.3% accurate, 0.6× 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)}\\ \mathbf{if}\;\frac{c0}{2 \cdot w} \cdot \left(t\_0 + \sqrt{t\_0 \cdot t\_0 - M \cdot M}\right) \leq \infty:\\ \;\;\;\;-0.5 \cdot \left(\frac{c0}{h} \cdot \frac{c0 \cdot \left(\frac{{\left(\frac{d}{D}\right)}^{2}}{w} \cdot -2\right)}{w}\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 (/ (* c0 (* d d)) (* (* w h) (* D D)))))
   (if (<=
        (* (/ c0 (* 2.0 w)) (+ t_0 (sqrt (- (* t_0 t_0) (* M M)))))
        INFINITY)
     (* -0.5 (* (/ c0 h) (/ (* c0 (* (/ (pow (/ d D) 2.0) w) -2.0)) w)))
     (* c0 (/ 0.0 (* 2.0 w))))))
double code(double c0, double w, double h, double D, double d, double M) {
	double t_0 = (c0 * (d * d)) / ((w * h) * (D * D));
	double tmp;
	if (((c0 / (2.0 * w)) * (t_0 + sqrt(((t_0 * t_0) - (M * M))))) <= ((double) INFINITY)) {
		tmp = -0.5 * ((c0 / h) * ((c0 * ((pow((d / D), 2.0) / w) * -2.0)) / w));
	} else {
		tmp = c0 * (0.0 / (2.0 * w));
	}
	return tmp;
}
public static double code(double c0, double w, double h, double D, double d, double M) {
	double t_0 = (c0 * (d * d)) / ((w * h) * (D * D));
	double tmp;
	if (((c0 / (2.0 * w)) * (t_0 + Math.sqrt(((t_0 * t_0) - (M * M))))) <= Double.POSITIVE_INFINITY) {
		tmp = -0.5 * ((c0 / h) * ((c0 * ((Math.pow((d / D), 2.0) / w) * -2.0)) / w));
	} else {
		tmp = c0 * (0.0 / (2.0 * w));
	}
	return tmp;
}
def code(c0, w, h, D, d, M):
	t_0 = (c0 * (d * d)) / ((w * h) * (D * D))
	tmp = 0
	if ((c0 / (2.0 * w)) * (t_0 + math.sqrt(((t_0 * t_0) - (M * M))))) <= math.inf:
		tmp = -0.5 * ((c0 / h) * ((c0 * ((math.pow((d / D), 2.0) / w) * -2.0)) / w))
	else:
		tmp = c0 * (0.0 / (2.0 * w))
	return tmp
function code(c0, w, h, D, d, M)
	t_0 = Float64(Float64(c0 * Float64(d * d)) / Float64(Float64(w * h) * Float64(D * D)))
	tmp = 0.0
	if (Float64(Float64(c0 / Float64(2.0 * w)) * Float64(t_0 + sqrt(Float64(Float64(t_0 * t_0) - Float64(M * M))))) <= Inf)
		tmp = Float64(-0.5 * Float64(Float64(c0 / h) * Float64(Float64(c0 * Float64(Float64((Float64(d / D) ^ 2.0) / w) * -2.0)) / w)));
	else
		tmp = Float64(c0 * Float64(0.0 / Float64(2.0 * w)));
	end
	return tmp
end
function tmp_2 = code(c0, w, h, D, d, M)
	t_0 = (c0 * (d * d)) / ((w * h) * (D * D));
	tmp = 0.0;
	if (((c0 / (2.0 * w)) * (t_0 + sqrt(((t_0 * t_0) - (M * M))))) <= Inf)
		tmp = -0.5 * ((c0 / h) * ((c0 * ((((d / D) ^ 2.0) / w) * -2.0)) / w));
	else
		tmp = c0 * (0.0 / (2.0 * w));
	end
	tmp_2 = tmp;
end
code[c0_, w_, h_, D_, d_, M_] := Block[{t$95$0 = N[(N[(c0 * N[(d * d), $MachinePrecision]), $MachinePrecision] / N[(N[(w * h), $MachinePrecision] * N[(D * D), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[(c0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision] * N[(t$95$0 + N[Sqrt[N[(N[(t$95$0 * t$95$0), $MachinePrecision] - N[(M * M), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], Infinity], N[(-0.5 * N[(N[(c0 / h), $MachinePrecision] * N[(N[(c0 * N[(N[(N[Power[N[(d / D), $MachinePrecision], 2.0], $MachinePrecision] / w), $MachinePrecision] * -2.0), $MachinePrecision]), $MachinePrecision] / w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(c0 * N[(0.0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}\\
\mathbf{if}\;\frac{c0}{2 \cdot w} \cdot \left(t\_0 + \sqrt{t\_0 \cdot t\_0 - M \cdot M}\right) \leq \infty:\\
\;\;\;\;-0.5 \cdot \left(\frac{c0}{h} \cdot \frac{c0 \cdot \left(\frac{{\left(\frac{d}{D}\right)}^{2}}{w} \cdot -2\right)}{w}\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 75.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. Simplified72.2%

      \[\leadsto \color{blue}{c0 \cdot \frac{\mathsf{fma}\left(c0, d \cdot \frac{d}{D \cdot \left(w \cdot \left(h \cdot D\right)\right)}, \sqrt{\mathsf{fma}\left(c0, d \cdot \frac{d}{D \cdot \left(w \cdot \left(h \cdot D\right)\right)}, M\right) \cdot \left(c0 \cdot \left(d \cdot \frac{d}{D \cdot \left(w \cdot \left(h \cdot D\right)\right)}\right) - M\right)}\right)}{2 \cdot w}} \]
    3. Add Preprocessing
    4. Taylor expanded in c0 around -inf 4.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}{-1 \cdot \frac{c0 \cdot {d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}}\right)}{2 \cdot w} \]
    5. Step-by-step derivation
      1. mul-1-neg4.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 \cdot {d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}}\right)}{2 \cdot w} \]
      2. associate-/l*4.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}{c0 \cdot \frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}}\right)}{2 \cdot w} \]
      3. distribute-rgt-neg-in4.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}{c0 \cdot \left(-\frac{{d}^{2}}{{D}^{2} \cdot \left(h \cdot w\right)}\right)}\right)}{2 \cdot w} \]
      4. *-commutative4.9%

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

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

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

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

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

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

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

        \[\leadsto c0 \cdot \frac{\mathsf{fma}\left(c0, d \cdot \frac{d}{D \cdot \left(w \cdot \left(h \cdot D\right)\right)}, c0 \cdot \frac{{d}^{2}}{{D}^{2} \cdot \color{blue}{\left(w \cdot \left(-h\right)\right)}}\right)}{2 \cdot w} \]
    6. Simplified4.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}{c0 \cdot \frac{{d}^{2}}{{D}^{2} \cdot \left(w \cdot \left(-h\right)\right)}}\right)}{2 \cdot w} \]
    7. Step-by-step derivation
      1. associate-*r/4.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 \cdot {d}^{2}}{{D}^{2} \cdot \left(w \cdot \left(-h\right)\right)}}\right)}{2 \cdot w} \]
      2. *-commutative4.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 \cdot {d}^{2}}{\color{blue}{\left(w \cdot \left(-h\right)\right) \cdot {D}^{2}}}\right)}{2 \cdot w} \]
      3. times-frac7.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}{\frac{c0}{w \cdot \left(-h\right)} \cdot \frac{{d}^{2}}{{D}^{2}}}\right)}{2 \cdot w} \]
      4. add-sqr-sqrt4.1%

        \[\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 \color{blue}{\left(\sqrt{-h} \cdot \sqrt{-h}\right)}} \cdot \frac{{d}^{2}}{{D}^{2}}\right)}{2 \cdot w} \]
      5. sqrt-unprod28.3%

        \[\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 \color{blue}{\sqrt{\left(-h\right) \cdot \left(-h\right)}}} \cdot \frac{{d}^{2}}{{D}^{2}}\right)}{2 \cdot w} \]
      6. sqr-neg28.3%

        \[\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 \sqrt{\color{blue}{h \cdot h}}} \cdot \frac{{d}^{2}}{{D}^{2}}\right)}{2 \cdot w} \]
      7. sqrt-unprod36.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 \color{blue}{\left(\sqrt{h} \cdot \sqrt{h}\right)}} \cdot \frac{{d}^{2}}{{D}^{2}}\right)}{2 \cdot w} \]
      8. add-sqr-sqrt71.0%

        \[\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 \color{blue}{h}} \cdot \frac{{d}^{2}}{{D}^{2}}\right)}{2 \cdot w} \]
      9. *-commutative71.0%

        \[\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}{\color{blue}{h \cdot w}} \cdot \frac{{d}^{2}}{{D}^{2}}\right)}{2 \cdot w} \]
      10. unpow271.0%

        \[\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}{h \cdot w} \cdot \frac{\color{blue}{d \cdot d}}{{D}^{2}}\right)}{2 \cdot w} \]
      11. unpow271.0%

        \[\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}{h \cdot w} \cdot \frac{d \cdot d}{\color{blue}{D \cdot D}}\right)}{2 \cdot w} \]
      12. frac-times72.3%

        \[\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}{h \cdot w} \cdot \color{blue}{\left(\frac{d}{D} \cdot \frac{d}{D}\right)}\right)}{2 \cdot w} \]
      13. unpow272.3%

        \[\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}{h \cdot w} \cdot \color{blue}{{\left(\frac{d}{D}\right)}^{2}}\right)}{2 \cdot w} \]
      14. add-sqr-sqrt71.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}{\sqrt{\frac{c0}{h \cdot w} \cdot {\left(\frac{d}{D}\right)}^{2}} \cdot \sqrt{\frac{c0}{h \cdot w} \cdot {\left(\frac{d}{D}\right)}^{2}}}\right)}{2 \cdot w} \]
      15. pow271.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}{{\left(\sqrt{\frac{c0}{h \cdot w} \cdot {\left(\frac{d}{D}\right)}^{2}}\right)}^{2}}\right)}{2 \cdot w} \]
    8. Applied egg-rr72.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{d}{D} \cdot \sqrt{\frac{\frac{c0}{w}}{h}}\right)}^{2}}\right)}{2 \cdot w} \]
    9. Taylor expanded in h around -inf 0.0%

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

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

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

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

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

      \[\leadsto \color{blue}{-0.5 \cdot \left(\frac{c0}{h} \cdot \frac{c0 \cdot \left(\frac{{\left(\frac{d}{D}\right)}^{2}}{w} \cdot -2\right)}{w}\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. Simplified20.5%

      \[\leadsto \color{blue}{c0 \cdot \frac{\mathsf{fma}\left(c0, d \cdot \frac{d}{D \cdot \left(w \cdot \left(h \cdot D\right)\right)}, \sqrt{\mathsf{fma}\left(c0, d \cdot \frac{d}{D \cdot \left(w \cdot \left(h \cdot D\right)\right)}, M\right) \cdot \left(c0 \cdot \left(d \cdot \frac{d}{D \cdot \left(w \cdot \left(h \cdot D\right)\right)}\right) - M\right)}\right)}{2 \cdot w}} \]
    3. Add Preprocessing
    4. Taylor expanded in c0 around -inf 0.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-in0.1%

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

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

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

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

        \[\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-lft38.9%

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

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

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

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

Alternative 3: 34.2% 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.4%

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

    \[\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-in1.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-neg1.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-in1.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*1.5%

      \[\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-neg1.5%

      \[\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*2.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-in2.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-eval2.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-lft30.2%

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

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

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

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

Reproduce

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