Henrywood and Agarwal, Equation (13)

Percentage Accurate: 24.4% → 56.0%
Time: 31.1s
Alternatives: 13
Speedup: 10.8×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 13 alternatives:

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

Initial Program: 24.4% 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: 56.0% accurate, 0.2× speedup?

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

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

\mathbf{elif}\;t\_2 \leq \infty:\\
\;\;\;\;{\left(d \cdot \frac{c0}{\sqrt{h} \cdot \left(w \cdot D\right)}\right)}^{2}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 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))))) < -0.0

    1. Initial program 67.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. Simplified64.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. Step-by-step derivation
      1. fma-undefine69.7%

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

        \[\leadsto c0 \cdot \frac{c0 \cdot \color{blue}{\frac{d \cdot 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)}}{2 \cdot w} \]
      3. *-commutative68.1%

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

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

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

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

        \[\leadsto c0 \cdot \frac{\color{blue}{\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}} + \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)}}{2 \cdot w} \]
      8. times-frac64.7%

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

        \[\leadsto c0 \cdot \frac{\frac{c0}{w \cdot h} \cdot \color{blue}{{\left(\frac{d}{D}\right)}^{2}} + \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)}}{2 \cdot w} \]
    5. Applied egg-rr70.6%

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

    if -0.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))))) < +inf.0

    1. Initial program 72.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\left(c0 \cdot d\right) \cdot \left(c0 \cdot d\right)}{\color{blue}{\left(w \cdot w\right)} \cdot \left(\left(D \cdot \sqrt{h}\right) \cdot \left(D \cdot \sqrt{h}\right)\right)} \]
      10. swap-sqr85.4%

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

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

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

        \[\leadsto \color{blue}{\left(c0 \cdot \frac{d}{w \cdot \left(D \cdot \sqrt{h}\right)}\right)} \cdot \left(c0 \cdot \frac{d}{w \cdot \left(D \cdot \sqrt{h}\right)}\right) \]
      14. unpow289.8%

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

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

    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. Simplified19.6%

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

      \[\leadsto c0 \cdot \color{blue}{\left(-0.5 \cdot \frac{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)}{w}\right)} \]
    5. Step-by-step derivation
      1. associate-/l*1.3%

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

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

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

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

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

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

        \[\leadsto c0 \cdot \left(-0.5 \cdot \frac{c0 \cdot \color{blue}{0}}{w}\right) \]
    8. Applied egg-rr41.7%

      \[\leadsto c0 \cdot \left(-0.5 \cdot \color{blue}{\frac{c0 \cdot 0}{w}}\right) \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 2: 54.3% accurate, 0.3× speedup?

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

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

\mathbf{elif}\;t\_2 \leq \infty:\\
\;\;\;\;{\left(d \cdot \frac{c0}{\sqrt{h} \cdot \left(w \cdot D\right)}\right)}^{2}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 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))))) < -9.9999999999999999e-110

    1. Initial program 71.7%

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

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

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

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

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

        \[\leadsto c0 \cdot \frac{\mathsf{fma}\left(c0, d \cdot {\left(\frac{\color{blue}{\left(\left(w \cdot h\right) \cdot D\right)} \cdot D}{d}\right)}^{-1}, \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} \]
      5. associate-*r*71.7%

        \[\leadsto c0 \cdot \frac{\mathsf{fma}\left(c0, d \cdot {\left(\frac{\color{blue}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}}{d}\right)}^{-1}, \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} \]
      6. associate-*l*74.5%

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

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

      \[\leadsto c0 \cdot \frac{\mathsf{fma}\left(c0, d \cdot \color{blue}{{\left(\frac{w \cdot \left(h \cdot {D}^{2}\right)}{d}\right)}^{-1}}, \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} \]
    6. Step-by-step derivation
      1. unpow-174.5%

        \[\leadsto c0 \cdot \frac{\mathsf{fma}\left(c0, d \cdot \color{blue}{\frac{1}{\frac{w \cdot \left(h \cdot {D}^{2}\right)}{d}}}, \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} \]
      2. associate-/l*74.5%

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

      \[\leadsto c0 \cdot \frac{\mathsf{fma}\left(c0, d \cdot \color{blue}{\frac{1}{w \cdot \frac{h \cdot {D}^{2}}{d}}}, \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} \]
    8. Step-by-step derivation
      1. un-div-inv74.5%

        \[\leadsto c0 \cdot \frac{\mathsf{fma}\left(c0, \color{blue}{\frac{d}{w \cdot \frac{h \cdot {D}^{2}}{d}}}, \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} \]
      2. associate-*r/74.6%

        \[\leadsto c0 \cdot \frac{\mathsf{fma}\left(c0, \frac{d}{\color{blue}{\frac{w \cdot \left(h \cdot {D}^{2}\right)}{d}}}, \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} \]
    9. Applied egg-rr74.6%

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

    if -9.9999999999999999e-110 < (*.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 68.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(c0 \cdot \frac{d}{w \cdot \left(D \cdot \sqrt{h}\right)}\right)} \cdot \left(c0 \cdot \frac{d}{w \cdot \left(D \cdot \sqrt{h}\right)}\right) \]
      14. unpow283.1%

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

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

    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. Simplified19.6%

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

      \[\leadsto c0 \cdot \color{blue}{\left(-0.5 \cdot \frac{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)}{w}\right)} \]
    5. Step-by-step derivation
      1. associate-/l*1.3%

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

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

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

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

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

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

        \[\leadsto c0 \cdot \left(-0.5 \cdot \frac{c0 \cdot \color{blue}{0}}{w}\right) \]
    8. Applied egg-rr41.7%

      \[\leadsto c0 \cdot \left(-0.5 \cdot \color{blue}{\frac{c0 \cdot 0}{w}}\right) \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 3: 54.2% accurate, 0.3× speedup?

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

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

\mathbf{elif}\;t\_2 \leq \infty:\\
\;\;\;\;{\left(d \cdot \frac{c0}{\sqrt{h} \cdot \left(w \cdot D\right)}\right)}^{2}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 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))))) < -9.9999999999999999e-110

    1. Initial program 71.7%

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

      \[\leadsto \color{blue}{c0 \cdot \frac{\mathsf{fma}\left(c0, d \cdot \frac{d}{D \cdot \left(w \cdot \left(h \cdot D\right)\right)}, \sqrt{\mathsf{fma}\left(c0, d \cdot \frac{d}{D \cdot \left(w \cdot \left(h \cdot D\right)\right)}, M\right) \cdot \left(c0 \cdot \left(d \cdot \frac{d}{D \cdot \left(w \cdot \left(h \cdot D\right)\right)}\right) - M\right)}\right)}{2 \cdot w}} \]
    3. Add Preprocessing
    4. Step-by-step derivation
      1. *-un-lft-identity74.4%

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

        \[\leadsto c0 \cdot \frac{\mathsf{fma}\left(c0, d \cdot \left(1 \cdot \frac{d}{\color{blue}{\left(w \cdot \left(h \cdot D\right)\right) \cdot D}}\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. associate-*r*71.6%

        \[\leadsto c0 \cdot \frac{\mathsf{fma}\left(c0, d \cdot \left(1 \cdot \frac{d}{\color{blue}{\left(\left(w \cdot h\right) \cdot D\right)} \cdot D}\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} \]
      4. associate-*r*71.6%

        \[\leadsto c0 \cdot \frac{\mathsf{fma}\left(c0, d \cdot \left(1 \cdot \frac{d}{\color{blue}{\left(w \cdot h\right) \cdot \left(D \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} \]
      5. associate-*l*74.5%

        \[\leadsto c0 \cdot \frac{\mathsf{fma}\left(c0, d \cdot \left(1 \cdot \frac{d}{\color{blue}{w \cdot \left(h \cdot \left(D \cdot D\right)\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} \]
      6. pow274.5%

        \[\leadsto c0 \cdot \frac{\mathsf{fma}\left(c0, d \cdot \left(1 \cdot \frac{d}{w \cdot \left(h \cdot \color{blue}{{D}^{2}}\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} \]
    5. Applied egg-rr74.5%

      \[\leadsto c0 \cdot \frac{\mathsf{fma}\left(c0, d \cdot \color{blue}{\left(1 \cdot \frac{d}{w \cdot \left(h \cdot {D}^{2}\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} \]
    6. Step-by-step derivation
      1. *-lft-identity74.5%

        \[\leadsto c0 \cdot \frac{\mathsf{fma}\left(c0, d \cdot \color{blue}{\frac{d}{w \cdot \left(h \cdot {D}^{2}\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} \]
      2. associate-/r*74.5%

        \[\leadsto c0 \cdot \frac{\mathsf{fma}\left(c0, d \cdot \color{blue}{\frac{\frac{d}{w}}{h \cdot {D}^{2}}}, \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} \]
    7. Simplified74.5%

      \[\leadsto c0 \cdot \frac{\mathsf{fma}\left(c0, d \cdot \color{blue}{\frac{\frac{d}{w}}{h \cdot {D}^{2}}}, \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} \]

    if -9.9999999999999999e-110 < (*.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 68.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(c0 \cdot \frac{d}{w \cdot \left(D \cdot \sqrt{h}\right)}\right)} \cdot \left(c0 \cdot \frac{d}{w \cdot \left(D \cdot \sqrt{h}\right)}\right) \]
      14. unpow283.1%

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

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

    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. Simplified19.6%

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

      \[\leadsto c0 \cdot \color{blue}{\left(-0.5 \cdot \frac{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)}{w}\right)} \]
    5. Step-by-step derivation
      1. associate-/l*1.3%

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

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

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

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

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

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

        \[\leadsto c0 \cdot \left(-0.5 \cdot \frac{c0 \cdot \color{blue}{0}}{w}\right) \]
    8. Applied egg-rr41.7%

      \[\leadsto c0 \cdot \left(-0.5 \cdot \color{blue}{\frac{c0 \cdot 0}{w}}\right) \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 4: 54.6% accurate, 0.3× speedup?

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

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

\mathbf{elif}\;t\_2 \leq \infty:\\
\;\;\;\;{\left(d \cdot \frac{c0}{\sqrt{h} \cdot \left(w \cdot D\right)}\right)}^{2}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 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))))) < -9.9999999999999999e-110

    1. Initial program 71.7%

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

      \[\leadsto \color{blue}{c0 \cdot \frac{\mathsf{fma}\left(c0, d \cdot \frac{d}{D \cdot \left(w \cdot \left(h \cdot D\right)\right)}, \sqrt{\mathsf{fma}\left(c0, d \cdot \frac{d}{D \cdot \left(w \cdot \left(h \cdot D\right)\right)}, M\right) \cdot \left(c0 \cdot \left(d \cdot \frac{d}{D \cdot \left(w \cdot \left(h \cdot D\right)\right)}\right) - M\right)}\right)}{2 \cdot w}} \]
    3. Add Preprocessing

    if -9.9999999999999999e-110 < (*.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 68.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(c0 \cdot \frac{d}{w \cdot \left(D \cdot \sqrt{h}\right)}\right)} \cdot \left(c0 \cdot \frac{d}{w \cdot \left(D \cdot \sqrt{h}\right)}\right) \]
      14. unpow283.1%

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

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

    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. Simplified19.6%

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

      \[\leadsto c0 \cdot \color{blue}{\left(-0.5 \cdot \frac{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)}{w}\right)} \]
    5. Step-by-step derivation
      1. associate-/l*1.3%

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

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

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

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

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

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

        \[\leadsto c0 \cdot \left(-0.5 \cdot \frac{c0 \cdot \color{blue}{0}}{w}\right) \]
    8. Applied egg-rr41.7%

      \[\leadsto c0 \cdot \left(-0.5 \cdot \color{blue}{\frac{c0 \cdot 0}{w}}\right) \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 5: 56.2% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}\\ t_1 := \frac{c0}{2 \cdot w} \cdot \left(t\_0 + \sqrt{t\_0 \cdot t\_0 - M \cdot M}\right)\\ \mathbf{if}\;t\_1 \leq 0:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_1 \leq \infty:\\ \;\;\;\;{\left(d \cdot \frac{c0}{\sqrt{h} \cdot \left(w \cdot D\right)}\right)}^{2}\\ \mathbf{else}:\\ \;\;\;\;c0 \cdot \left(-0.5 \cdot \frac{c0 \cdot 0}{w}\right)\\ \end{array} \end{array} \]
(FPCore (c0 w h D d M)
 :precision binary64
 (let* ((t_0 (/ (* c0 (* d d)) (* (* w h) (* D D))))
        (t_1 (* (/ c0 (* 2.0 w)) (+ t_0 (sqrt (- (* t_0 t_0) (* M M)))))))
   (if (<= t_1 0.0)
     t_1
     (if (<= t_1 INFINITY)
       (pow (* d (/ c0 (* (sqrt h) (* w D)))) 2.0)
       (* c0 (* -0.5 (/ (* c0 0.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 t_1 = (c0 / (2.0 * w)) * (t_0 + sqrt(((t_0 * t_0) - (M * M))));
	double tmp;
	if (t_1 <= 0.0) {
		tmp = t_1;
	} else if (t_1 <= ((double) INFINITY)) {
		tmp = pow((d * (c0 / (sqrt(h) * (w * D)))), 2.0);
	} else {
		tmp = c0 * (-0.5 * ((c0 * 0.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 t_1 = (c0 / (2.0 * w)) * (t_0 + Math.sqrt(((t_0 * t_0) - (M * M))));
	double tmp;
	if (t_1 <= 0.0) {
		tmp = t_1;
	} else if (t_1 <= Double.POSITIVE_INFINITY) {
		tmp = Math.pow((d * (c0 / (Math.sqrt(h) * (w * D)))), 2.0);
	} else {
		tmp = c0 * (-0.5 * ((c0 * 0.0) / w));
	}
	return tmp;
}
def code(c0, w, h, D, d, M):
	t_0 = (c0 * (d * d)) / ((w * h) * (D * D))
	t_1 = (c0 / (2.0 * w)) * (t_0 + math.sqrt(((t_0 * t_0) - (M * M))))
	tmp = 0
	if t_1 <= 0.0:
		tmp = t_1
	elif t_1 <= math.inf:
		tmp = math.pow((d * (c0 / (math.sqrt(h) * (w * D)))), 2.0)
	else:
		tmp = c0 * (-0.5 * ((c0 * 0.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)))
	t_1 = Float64(Float64(c0 / Float64(2.0 * w)) * Float64(t_0 + sqrt(Float64(Float64(t_0 * t_0) - Float64(M * M)))))
	tmp = 0.0
	if (t_1 <= 0.0)
		tmp = t_1;
	elseif (t_1 <= Inf)
		tmp = Float64(d * Float64(c0 / Float64(sqrt(h) * Float64(w * D)))) ^ 2.0;
	else
		tmp = Float64(c0 * Float64(-0.5 * Float64(Float64(c0 * 0.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));
	t_1 = (c0 / (2.0 * w)) * (t_0 + sqrt(((t_0 * t_0) - (M * M))));
	tmp = 0.0;
	if (t_1 <= 0.0)
		tmp = t_1;
	elseif (t_1 <= Inf)
		tmp = (d * (c0 / (sqrt(h) * (w * D)))) ^ 2.0;
	else
		tmp = c0 * (-0.5 * ((c0 * 0.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]}, Block[{t$95$1 = N[(N[(c0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision] * N[(t$95$0 + N[Sqrt[N[(N[(t$95$0 * t$95$0), $MachinePrecision] - N[(M * M), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, 0.0], t$95$1, If[LessEqual[t$95$1, Infinity], N[Power[N[(d * N[(c0 / N[(N[Sqrt[h], $MachinePrecision] * N[(w * D), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision], N[(c0 * N[(-0.5 * N[(N[(c0 * 0.0), $MachinePrecision] / 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)}\\
t_1 := \frac{c0}{2 \cdot w} \cdot \left(t\_0 + \sqrt{t\_0 \cdot t\_0 - M \cdot M}\right)\\
\mathbf{if}\;t\_1 \leq 0:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;t\_1 \leq \infty:\\
\;\;\;\;{\left(d \cdot \frac{c0}{\sqrt{h} \cdot \left(w \cdot D\right)}\right)}^{2}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 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))))) < -0.0

    1. Initial program 67.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. Add Preprocessing

    if -0.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))))) < +inf.0

    1. Initial program 72.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\left(c0 \cdot d\right) \cdot \left(c0 \cdot d\right)}{\color{blue}{\left(w \cdot w\right)} \cdot \left(\left(D \cdot \sqrt{h}\right) \cdot \left(D \cdot \sqrt{h}\right)\right)} \]
      10. swap-sqr85.4%

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

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

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

        \[\leadsto \color{blue}{\left(c0 \cdot \frac{d}{w \cdot \left(D \cdot \sqrt{h}\right)}\right)} \cdot \left(c0 \cdot \frac{d}{w \cdot \left(D \cdot \sqrt{h}\right)}\right) \]
      14. unpow289.8%

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

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

    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. Simplified19.6%

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

      \[\leadsto c0 \cdot \color{blue}{\left(-0.5 \cdot \frac{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)}{w}\right)} \]
    5. Step-by-step derivation
      1. associate-/l*1.3%

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

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

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

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

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

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

        \[\leadsto c0 \cdot \left(-0.5 \cdot \frac{c0 \cdot \color{blue}{0}}{w}\right) \]
    8. Applied egg-rr41.7%

      \[\leadsto c0 \cdot \left(-0.5 \cdot \color{blue}{\frac{c0 \cdot 0}{w}}\right) \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 6: 56.0% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}\\ t_1 := \frac{c0}{2 \cdot w} \cdot \left(t\_0 + \sqrt{t\_0 \cdot t\_0 - M \cdot M}\right)\\ \mathbf{if}\;t\_1 \leq 0:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_1 \leq \infty:\\ \;\;\;\;{\left(c0 \cdot \frac{d}{w \cdot \left(D \cdot \sqrt{h}\right)}\right)}^{2}\\ \mathbf{else}:\\ \;\;\;\;c0 \cdot \left(-0.5 \cdot \frac{c0 \cdot 0}{w}\right)\\ \end{array} \end{array} \]
(FPCore (c0 w h D d M)
 :precision binary64
 (let* ((t_0 (/ (* c0 (* d d)) (* (* w h) (* D D))))
        (t_1 (* (/ c0 (* 2.0 w)) (+ t_0 (sqrt (- (* t_0 t_0) (* M M)))))))
   (if (<= t_1 0.0)
     t_1
     (if (<= t_1 INFINITY)
       (pow (* c0 (/ d (* w (* D (sqrt h))))) 2.0)
       (* c0 (* -0.5 (/ (* c0 0.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 t_1 = (c0 / (2.0 * w)) * (t_0 + sqrt(((t_0 * t_0) - (M * M))));
	double tmp;
	if (t_1 <= 0.0) {
		tmp = t_1;
	} else if (t_1 <= ((double) INFINITY)) {
		tmp = pow((c0 * (d / (w * (D * sqrt(h))))), 2.0);
	} else {
		tmp = c0 * (-0.5 * ((c0 * 0.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 t_1 = (c0 / (2.0 * w)) * (t_0 + Math.sqrt(((t_0 * t_0) - (M * M))));
	double tmp;
	if (t_1 <= 0.0) {
		tmp = t_1;
	} else if (t_1 <= Double.POSITIVE_INFINITY) {
		tmp = Math.pow((c0 * (d / (w * (D * Math.sqrt(h))))), 2.0);
	} else {
		tmp = c0 * (-0.5 * ((c0 * 0.0) / w));
	}
	return tmp;
}
def code(c0, w, h, D, d, M):
	t_0 = (c0 * (d * d)) / ((w * h) * (D * D))
	t_1 = (c0 / (2.0 * w)) * (t_0 + math.sqrt(((t_0 * t_0) - (M * M))))
	tmp = 0
	if t_1 <= 0.0:
		tmp = t_1
	elif t_1 <= math.inf:
		tmp = math.pow((c0 * (d / (w * (D * math.sqrt(h))))), 2.0)
	else:
		tmp = c0 * (-0.5 * ((c0 * 0.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)))
	t_1 = Float64(Float64(c0 / Float64(2.0 * w)) * Float64(t_0 + sqrt(Float64(Float64(t_0 * t_0) - Float64(M * M)))))
	tmp = 0.0
	if (t_1 <= 0.0)
		tmp = t_1;
	elseif (t_1 <= Inf)
		tmp = Float64(c0 * Float64(d / Float64(w * Float64(D * sqrt(h))))) ^ 2.0;
	else
		tmp = Float64(c0 * Float64(-0.5 * Float64(Float64(c0 * 0.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));
	t_1 = (c0 / (2.0 * w)) * (t_0 + sqrt(((t_0 * t_0) - (M * M))));
	tmp = 0.0;
	if (t_1 <= 0.0)
		tmp = t_1;
	elseif (t_1 <= Inf)
		tmp = (c0 * (d / (w * (D * sqrt(h))))) ^ 2.0;
	else
		tmp = c0 * (-0.5 * ((c0 * 0.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]}, Block[{t$95$1 = N[(N[(c0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision] * N[(t$95$0 + N[Sqrt[N[(N[(t$95$0 * t$95$0), $MachinePrecision] - N[(M * M), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, 0.0], t$95$1, If[LessEqual[t$95$1, Infinity], N[Power[N[(c0 * N[(d / N[(w * N[(D * N[Sqrt[h], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision], N[(c0 * N[(-0.5 * N[(N[(c0 * 0.0), $MachinePrecision] / 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)}\\
t_1 := \frac{c0}{2 \cdot w} \cdot \left(t\_0 + \sqrt{t\_0 \cdot t\_0 - M \cdot M}\right)\\
\mathbf{if}\;t\_1 \leq 0:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;t\_1 \leq \infty:\\
\;\;\;\;{\left(c0 \cdot \frac{d}{w \cdot \left(D \cdot \sqrt{h}\right)}\right)}^{2}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 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))))) < -0.0

    1. Initial program 67.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. Add Preprocessing

    if -0.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))))) < +inf.0

    1. Initial program 72.7%

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

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

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

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

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

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

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

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

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

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

    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. Simplified19.6%

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

      \[\leadsto c0 \cdot \color{blue}{\left(-0.5 \cdot \frac{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)}{w}\right)} \]
    5. Step-by-step derivation
      1. associate-/l*1.3%

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

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

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

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

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

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

        \[\leadsto c0 \cdot \left(-0.5 \cdot \frac{c0 \cdot \color{blue}{0}}{w}\right) \]
    8. Applied egg-rr41.7%

      \[\leadsto c0 \cdot \left(-0.5 \cdot \color{blue}{\frac{c0 \cdot 0}{w}}\right) \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 7: 54.3% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}\\ t_1 := \frac{c0}{2 \cdot w} \cdot \left(t\_0 + \sqrt{t\_0 \cdot t\_0 - M \cdot M}\right)\\ \mathbf{if}\;t\_1 \leq \infty:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;c0 \cdot \left(-0.5 \cdot \frac{c0 \cdot 0}{w}\right)\\ \end{array} \end{array} \]
(FPCore (c0 w h D d M)
 :precision binary64
 (let* ((t_0 (/ (* c0 (* d d)) (* (* w h) (* D D))))
        (t_1 (* (/ c0 (* 2.0 w)) (+ t_0 (sqrt (- (* t_0 t_0) (* M M)))))))
   (if (<= t_1 INFINITY) t_1 (* c0 (* -0.5 (/ (* c0 0.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 t_1 = (c0 / (2.0 * w)) * (t_0 + sqrt(((t_0 * t_0) - (M * M))));
	double tmp;
	if (t_1 <= ((double) INFINITY)) {
		tmp = t_1;
	} else {
		tmp = c0 * (-0.5 * ((c0 * 0.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 t_1 = (c0 / (2.0 * w)) * (t_0 + Math.sqrt(((t_0 * t_0) - (M * M))));
	double tmp;
	if (t_1 <= Double.POSITIVE_INFINITY) {
		tmp = t_1;
	} else {
		tmp = c0 * (-0.5 * ((c0 * 0.0) / w));
	}
	return tmp;
}
def code(c0, w, h, D, d, M):
	t_0 = (c0 * (d * d)) / ((w * h) * (D * D))
	t_1 = (c0 / (2.0 * w)) * (t_0 + math.sqrt(((t_0 * t_0) - (M * M))))
	tmp = 0
	if t_1 <= math.inf:
		tmp = t_1
	else:
		tmp = c0 * (-0.5 * ((c0 * 0.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)))
	t_1 = Float64(Float64(c0 / Float64(2.0 * w)) * Float64(t_0 + sqrt(Float64(Float64(t_0 * t_0) - Float64(M * M)))))
	tmp = 0.0
	if (t_1 <= Inf)
		tmp = t_1;
	else
		tmp = Float64(c0 * Float64(-0.5 * Float64(Float64(c0 * 0.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));
	t_1 = (c0 / (2.0 * w)) * (t_0 + sqrt(((t_0 * t_0) - (M * M))));
	tmp = 0.0;
	if (t_1 <= Inf)
		tmp = t_1;
	else
		tmp = c0 * (-0.5 * ((c0 * 0.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]}, Block[{t$95$1 = N[(N[(c0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision] * N[(t$95$0 + N[Sqrt[N[(N[(t$95$0 * t$95$0), $MachinePrecision] - N[(M * M), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, Infinity], t$95$1, N[(c0 * N[(-0.5 * N[(N[(c0 * 0.0), $MachinePrecision] / 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)}\\
t_1 := \frac{c0}{2 \cdot w} \cdot \left(t\_0 + \sqrt{t\_0 \cdot t\_0 - M \cdot M}\right)\\
\mathbf{if}\;t\_1 \leq \infty:\\
\;\;\;\;t\_1\\

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


\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 70.0%

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

    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. Simplified19.6%

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

      \[\leadsto c0 \cdot \color{blue}{\left(-0.5 \cdot \frac{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)}{w}\right)} \]
    5. Step-by-step derivation
      1. associate-/l*1.3%

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

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

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

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

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

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

        \[\leadsto c0 \cdot \left(-0.5 \cdot \frac{c0 \cdot \color{blue}{0}}{w}\right) \]
    8. Applied egg-rr41.7%

      \[\leadsto c0 \cdot \left(-0.5 \cdot \color{blue}{\frac{c0 \cdot 0}{w}}\right) \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 8: 36.9% accurate, 1.2× speedup?

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

\\
\begin{array}{l}
t_0 := {\left(\frac{d}{D}\right)}^{2}\\
\mathbf{if}\;d \leq 2.5 \cdot 10^{+25}:\\
\;\;\;\;c0 \cdot \frac{\frac{c0}{w \cdot h} \cdot t\_0}{2 \cdot w}\\

\mathbf{elif}\;d \leq 4 \cdot 10^{+117} \lor \neg \left(d \leq 8.5 \cdot 10^{+270}\right):\\
\;\;\;\;c0 \cdot \left(-0.5 \cdot \frac{c0 \cdot 0}{w}\right)\\

\mathbf{else}:\\
\;\;\;\;c0 \cdot \frac{c0 \cdot \frac{t\_0}{w \cdot h}}{2 \cdot w}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < 2.50000000000000012e25

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.50000000000000012e25 < d < 4.0000000000000002e117 or 8.50000000000000063e270 < d

    1. Initial program 9.8%

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

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

      \[\leadsto c0 \cdot \color{blue}{\left(-0.5 \cdot \frac{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)}{w}\right)} \]
    5. Step-by-step derivation
      1. associate-/l*6.3%

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

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

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

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

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

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

        \[\leadsto c0 \cdot \left(-0.5 \cdot \frac{c0 \cdot \color{blue}{0}}{w}\right) \]
    8. Applied egg-rr56.7%

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

    if 4.0000000000000002e117 < d < 8.50000000000000063e270

    1. Initial program 28.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq 2.5 \cdot 10^{+25}:\\ \;\;\;\;c0 \cdot \frac{\frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2}}{2 \cdot w}\\ \mathbf{elif}\;d \leq 4 \cdot 10^{+117} \lor \neg \left(d \leq 8.5 \cdot 10^{+270}\right):\\ \;\;\;\;c0 \cdot \left(-0.5 \cdot \frac{c0 \cdot 0}{w}\right)\\ \mathbf{else}:\\ \;\;\;\;c0 \cdot \frac{c0 \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{w \cdot h}}{2 \cdot w}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 37.0% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq 1.12 \cdot 10^{+24} \lor \neg \left(d \leq 2 \cdot 10^{+118}\right) \land d \leq 2.5 \cdot 10^{+270}:\\ \;\;\;\;c0 \cdot \frac{c0 \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{w \cdot h}}{2 \cdot w}\\ \mathbf{else}:\\ \;\;\;\;c0 \cdot \left(-0.5 \cdot \frac{c0 \cdot 0}{w}\right)\\ \end{array} \end{array} \]
(FPCore (c0 w h D d M)
 :precision binary64
 (if (or (<= d 1.12e+24) (and (not (<= d 2e+118)) (<= d 2.5e+270)))
   (* c0 (/ (* c0 (/ (pow (/ d D) 2.0) (* w h))) (* 2.0 w)))
   (* c0 (* -0.5 (/ (* c0 0.0) w)))))
double code(double c0, double w, double h, double D, double d, double M) {
	double tmp;
	if ((d <= 1.12e+24) || (!(d <= 2e+118) && (d <= 2.5e+270))) {
		tmp = c0 * ((c0 * (pow((d / D), 2.0) / (w * h))) / (2.0 * w));
	} else {
		tmp = c0 * (-0.5 * ((c0 * 0.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 ((d_1 <= 1.12d+24) .or. (.not. (d_1 <= 2d+118)) .and. (d_1 <= 2.5d+270)) then
        tmp = c0 * ((c0 * (((d_1 / d) ** 2.0d0) / (w * h))) / (2.0d0 * w))
    else
        tmp = c0 * ((-0.5d0) * ((c0 * 0.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 ((d <= 1.12e+24) || (!(d <= 2e+118) && (d <= 2.5e+270))) {
		tmp = c0 * ((c0 * (Math.pow((d / D), 2.0) / (w * h))) / (2.0 * w));
	} else {
		tmp = c0 * (-0.5 * ((c0 * 0.0) / w));
	}
	return tmp;
}
def code(c0, w, h, D, d, M):
	tmp = 0
	if (d <= 1.12e+24) or (not (d <= 2e+118) and (d <= 2.5e+270)):
		tmp = c0 * ((c0 * (math.pow((d / D), 2.0) / (w * h))) / (2.0 * w))
	else:
		tmp = c0 * (-0.5 * ((c0 * 0.0) / w))
	return tmp
function code(c0, w, h, D, d, M)
	tmp = 0.0
	if ((d <= 1.12e+24) || (!(d <= 2e+118) && (d <= 2.5e+270)))
		tmp = Float64(c0 * Float64(Float64(c0 * Float64((Float64(d / D) ^ 2.0) / Float64(w * h))) / Float64(2.0 * w)));
	else
		tmp = Float64(c0 * Float64(-0.5 * Float64(Float64(c0 * 0.0) / w)));
	end
	return tmp
end
function tmp_2 = code(c0, w, h, D, d, M)
	tmp = 0.0;
	if ((d <= 1.12e+24) || (~((d <= 2e+118)) && (d <= 2.5e+270)))
		tmp = c0 * ((c0 * (((d / D) ^ 2.0) / (w * h))) / (2.0 * w));
	else
		tmp = c0 * (-0.5 * ((c0 * 0.0) / w));
	end
	tmp_2 = tmp;
end
code[c0_, w_, h_, D_, d_, M_] := If[Or[LessEqual[d, 1.12e+24], And[N[Not[LessEqual[d, 2e+118]], $MachinePrecision], LessEqual[d, 2.5e+270]]], N[(c0 * N[(N[(c0 * N[(N[Power[N[(d / D), $MachinePrecision], 2.0], $MachinePrecision] / N[(w * h), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(2.0 * w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(c0 * N[(-0.5 * N[(N[(c0 * 0.0), $MachinePrecision] / w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d \leq 1.12 \cdot 10^{+24} \lor \neg \left(d \leq 2 \cdot 10^{+118}\right) \land d \leq 2.5 \cdot 10^{+270}:\\
\;\;\;\;c0 \cdot \frac{c0 \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{w \cdot h}}{2 \cdot w}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < 1.12e24 or 1.99999999999999993e118 < d < 2.49999999999999988e270

    1. Initial program 24.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. Simplified37.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.12e24 < d < 1.99999999999999993e118 or 2.49999999999999988e270 < d

    1. Initial program 9.8%

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

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

      \[\leadsto c0 \cdot \color{blue}{\left(-0.5 \cdot \frac{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)}{w}\right)} \]
    5. Step-by-step derivation
      1. associate-/l*6.3%

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

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

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

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

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

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

        \[\leadsto c0 \cdot \left(-0.5 \cdot \frac{c0 \cdot \color{blue}{0}}{w}\right) \]
    8. Applied egg-rr56.7%

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

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

Alternative 10: 38.1% accurate, 1.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq 8.6 \cdot 10^{+24} \lor \neg \left(d \leq 4.9 \cdot 10^{+117}\right):\\
\;\;\;\;c0 \cdot \frac{\mathsf{fma}\left(c0, d \cdot \frac{d}{D \cdot \left(w \cdot \left(h \cdot D\right)\right)}, M\right)}{2 \cdot w}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < 8.59999999999999975e24 or 4.9000000000000001e117 < d

    1. Initial program 23.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 8.59999999999999975e24 < d < 4.9000000000000001e117

    1. Initial program 14.0%

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

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

      \[\leadsto c0 \cdot \color{blue}{\left(-0.5 \cdot \frac{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)}{w}\right)} \]
    5. Step-by-step derivation
      1. associate-/l*9.1%

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

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

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

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

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

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

        \[\leadsto c0 \cdot \left(-0.5 \cdot \frac{c0 \cdot \color{blue}{0}}{w}\right) \]
    8. Applied egg-rr53.9%

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

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

Alternative 11: 35.3% accurate, 10.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;M \leq 4.8 \cdot 10^{+142}:\\
\;\;\;\;c0 \cdot \left(-0.5 \cdot \frac{c0 \cdot 0}{w}\right)\\

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


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

    1. Initial program 25.7%

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

      \[\leadsto c0 \cdot \color{blue}{\left(-0.5 \cdot \frac{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)}{w}\right)} \]
    5. Step-by-step derivation
      1. associate-/l*2.6%

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

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

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

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

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

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

        \[\leadsto c0 \cdot \left(-0.5 \cdot \frac{c0 \cdot \color{blue}{0}}{w}\right) \]
    8. Applied egg-rr31.5%

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

    if 4.7999999999999998e142 < 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. Simplified37.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 \mathsf{fma}\left(\frac{c0}{w \cdot \left(h \cdot D\right)}, \frac{d \cdot d}{D}, -M\right)}\right)}{2 \cdot w}} \]
    3. Add Preprocessing
    4. Taylor expanded in w around -inf 0.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto c0 \cdot \color{blue}{\frac{0.5 \cdot M}{w}} \]
      2. *-commutative28.4%

        \[\leadsto c0 \cdot \frac{\color{blue}{M \cdot 0.5}}{w} \]
      3. associate-*r/28.4%

        \[\leadsto c0 \cdot \color{blue}{\left(M \cdot \frac{0.5}{w}\right)} \]
    13. Simplified28.4%

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

Alternative 12: 18.7% accurate, 21.6× speedup?

\[\begin{array}{l} \\ c0 \cdot \left(M \cdot \frac{0.5}{w}\right) \end{array} \]
(FPCore (c0 w h D d M) :precision binary64 (* c0 (* M (/ 0.5 w))))
double code(double c0, double w, double h, double D, double d, double M) {
	return c0 * (M * (0.5 / 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 * (m * (0.5d0 / w))
end function
public static double code(double c0, double w, double h, double D, double d, double M) {
	return c0 * (M * (0.5 / w));
}
def code(c0, w, h, D, d, M):
	return c0 * (M * (0.5 / w))
function code(c0, w, h, D, d, M)
	return Float64(c0 * Float64(M * Float64(0.5 / w)))
end
function tmp = code(c0, w, h, D, d, M)
	tmp = c0 * (M * (0.5 / w));
end
code[c0_, w_, h_, D_, d_, M_] := N[(c0 * N[(M * N[(0.5 / w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
c0 \cdot \left(M \cdot \frac{0.5}{w}\right)
\end{array}
Derivation
  1. Initial program 22.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto c0 \cdot \color{blue}{\frac{0.5 \cdot M}{w}} \]
    2. *-commutative15.6%

      \[\leadsto c0 \cdot \frac{\color{blue}{M \cdot 0.5}}{w} \]
    3. associate-*r/15.6%

      \[\leadsto c0 \cdot \color{blue}{\left(M \cdot \frac{0.5}{w}\right)} \]
  13. Simplified15.6%

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

Alternative 13: 18.2% accurate, 21.6× speedup?

\[\begin{array}{l} \\ M \cdot \frac{c0 \cdot 0.5}{w} \end{array} \]
(FPCore (c0 w h D d M) :precision binary64 (* M (/ (* c0 0.5) w)))
double code(double c0, double w, double h, double D, double d, double M) {
	return M * ((c0 * 0.5) / 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 = m * ((c0 * 0.5d0) / w)
end function
public static double code(double c0, double w, double h, double D, double d, double M) {
	return M * ((c0 * 0.5) / w);
}
def code(c0, w, h, D, d, M):
	return M * ((c0 * 0.5) / w)
function code(c0, w, h, D, d, M)
	return Float64(M * Float64(Float64(c0 * 0.5) / w))
end
function tmp = code(c0, w, h, D, d, M)
	tmp = M * ((c0 * 0.5) / w);
end
code[c0_, w_, h_, D_, d_, M_] := N[(M * N[(N[(c0 * 0.5), $MachinePrecision] / w), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
M \cdot \frac{c0 \cdot 0.5}{w}
\end{array}
Derivation
  1. Initial program 22.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{0.5 \cdot \frac{M \cdot c0}{w}} \]
  12. Step-by-step derivation
    1. *-commutative13.9%

      \[\leadsto \color{blue}{\frac{M \cdot c0}{w} \cdot 0.5} \]
    2. associate-/l*13.8%

      \[\leadsto \color{blue}{\left(M \cdot \frac{c0}{w}\right)} \cdot 0.5 \]
    3. associate-*r*13.8%

      \[\leadsto \color{blue}{M \cdot \left(\frac{c0}{w} \cdot 0.5\right)} \]
    4. associate-*l/13.8%

      \[\leadsto M \cdot \color{blue}{\frac{c0 \cdot 0.5}{w}} \]
  13. Simplified13.8%

    \[\leadsto \color{blue}{M \cdot \frac{c0 \cdot 0.5}{w}} \]
  14. Add Preprocessing

Reproduce

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