Henrywood and Agarwal, Equation (13)

Percentage Accurate: 24.5% → 53.0%
Time: 32.5s
Alternatives: 10
Speedup: 0.5×

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 10 alternatives:

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

Initial Program: 24.5% accurate, 1.0× speedup?

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

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

Alternative 1: 53.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(D \cdot D\right) \cdot \left(w \cdot h\right)}\\ \mathbf{if}\;\frac{c0}{2 \cdot w} \cdot \left(t\_1 + \sqrt{t\_1 \cdot t\_1 - M \cdot M}\right) \leq \infty:\\ \;\;\;\;c0 \cdot \frac{t\_0 + \sqrt{{t\_0}^{2} - {M}^{2}}}{2 \cdot w}\\ \mathbf{else}:\\ \;\;\;\;\log 1\\ \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)) (* (* D D) (* w h)))))
   (if (<=
        (* (/ c0 (* 2.0 w)) (+ t_1 (sqrt (- (* t_1 t_1) (* M M)))))
        INFINITY)
     (* c0 (/ (+ t_0 (sqrt (- (pow t_0 2.0) (pow M 2.0)))) (* 2.0 w)))
     (log 1.0))))
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)) / ((D * D) * (w * h));
	double tmp;
	if (((c0 / (2.0 * w)) * (t_1 + sqrt(((t_1 * t_1) - (M * M))))) <= ((double) INFINITY)) {
		tmp = c0 * ((t_0 + sqrt((pow(t_0, 2.0) - pow(M, 2.0)))) / (2.0 * w));
	} else {
		tmp = log(1.0);
	}
	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)) / ((D * D) * (w * h));
	double tmp;
	if (((c0 / (2.0 * w)) * (t_1 + Math.sqrt(((t_1 * t_1) - (M * M))))) <= Double.POSITIVE_INFINITY) {
		tmp = c0 * ((t_0 + Math.sqrt((Math.pow(t_0, 2.0) - Math.pow(M, 2.0)))) / (2.0 * w));
	} else {
		tmp = Math.log(1.0);
	}
	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)) / ((D * D) * (w * h))
	tmp = 0
	if ((c0 / (2.0 * w)) * (t_1 + math.sqrt(((t_1 * t_1) - (M * M))))) <= math.inf:
		tmp = c0 * ((t_0 + math.sqrt((math.pow(t_0, 2.0) - math.pow(M, 2.0)))) / (2.0 * w))
	else:
		tmp = math.log(1.0)
	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(D * D) * Float64(w * h)))
	tmp = 0.0
	if (Float64(Float64(c0 / Float64(2.0 * w)) * Float64(t_1 + sqrt(Float64(Float64(t_1 * t_1) - Float64(M * M))))) <= Inf)
		tmp = Float64(c0 * Float64(Float64(t_0 + sqrt(Float64((t_0 ^ 2.0) - (M ^ 2.0)))) / Float64(2.0 * w)));
	else
		tmp = log(1.0);
	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)) / ((D * D) * (w * h));
	tmp = 0.0;
	if (((c0 / (2.0 * w)) * (t_1 + sqrt(((t_1 * t_1) - (M * M))))) <= Inf)
		tmp = c0 * ((t_0 + sqrt(((t_0 ^ 2.0) - (M ^ 2.0)))) / (2.0 * w));
	else
		tmp = log(1.0);
	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[(D * D), $MachinePrecision] * N[(w * h), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[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], Infinity], 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], N[Log[1.0], $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(D \cdot D\right) \cdot \left(w \cdot h\right)}\\
\mathbf{if}\;\frac{c0}{2 \cdot w} \cdot \left(t\_1 + \sqrt{t\_1 \cdot t\_1 - M \cdot M}\right) \leq \infty:\\
\;\;\;\;c0 \cdot \frac{t\_0 + \sqrt{{t\_0}^{2} - {M}^{2}}}{2 \cdot w}\\

\mathbf{else}:\\
\;\;\;\;\log 1\\


\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 67.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. Simplified63.7%

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

        \[\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/66.2%

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

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

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

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

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

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

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

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

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

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

      \[\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{\frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2} - M}, \frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2}\right)} \]
    5. Step-by-step derivation
      1. fma-undefine25.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 27.0% accurate, 0.3× speedup?

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

\\
\begin{array}{l}
t_0 := \frac{c0}{w \cdot h}\\
t_1 := t\_0 \cdot {\left(\frac{d}{D}\right)}^{2}\\
t_2 := c0 \cdot \log \left({\left(1 + M \cdot 0.5\right)}^{\left(\frac{\sqrt{-1}}{w}\right)}\right)\\
t_3 := d \cdot \frac{d}{D \cdot \left(w \cdot \left(h \cdot D\right)\right)}\\
\mathbf{if}\;M \leq 2.8 \cdot 10^{-268}:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;M \leq 1.15 \cdot 10^{-155}:\\
\;\;\;\;c0 \cdot \frac{\mathsf{fma}\left(c0, t\_3, \sqrt{\mathsf{fma}\left(c0, t\_3, M\right) \cdot \left(c0 \cdot t\_3 - M\right)}\right)}{2 \cdot w}\\

\mathbf{elif}\;M \leq 9 \cdot 10^{-33}:\\
\;\;\;\;t\_2\\

\mathbf{else}:\\
\;\;\;\;\frac{c0}{2 \cdot w} \cdot \mathsf{fma}\left(\sqrt{M + t\_1}, \frac{d}{D} \cdot \sqrt{t\_0}, t\_1\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if M < 2.80000000000000015e-268 or 1.15000000000000003e-155 < M < 8.99999999999999982e-33

    1. Initial program 20.9%

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

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

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

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

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

      \[\leadsto c0 \cdot \color{blue}{\log \left({\left(e^{\frac{M}{2}}\right)}^{\left(\frac{\sqrt{-1}}{w}\right)}\right)} \]
    7. Taylor expanded in M around 0 32.1%

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

    if 2.80000000000000015e-268 < M < 1.15000000000000003e-155

    1. Initial program 46.9%

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

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

    if 8.99999999999999982e-33 < M

    1. Initial program 16.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. Simplified16.7%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;M \leq 2.8 \cdot 10^{-268}:\\ \;\;\;\;c0 \cdot \log \left({\left(1 + M \cdot 0.5\right)}^{\left(\frac{\sqrt{-1}}{w}\right)}\right)\\ \mathbf{elif}\;M \leq 1.15 \cdot 10^{-155}:\\ \;\;\;\;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}\\ \mathbf{elif}\;M \leq 9 \cdot 10^{-33}:\\ \;\;\;\;c0 \cdot \log \left({\left(1 + M \cdot 0.5\right)}^{\left(\frac{\sqrt{-1}}{w}\right)}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{c0}{2 \cdot w} \cdot \mathsf{fma}\left(\sqrt{M + \frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2}}, \frac{d}{D} \cdot \sqrt{\frac{c0}{w \cdot h}}, \frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 31.4% accurate, 0.3× speedup?

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

\\
\begin{array}{l}
t_0 := {\left(\frac{d}{D}\right)}^{2}\\
t_1 := \frac{c0}{w \cdot h} \cdot t\_0\\
t_2 := c0 \cdot \log \left({\left(1 + M \cdot 0.5\right)}^{\left(\frac{\sqrt{-1}}{w}\right)}\right)\\
t_3 := d \cdot \frac{d}{D \cdot \left(w \cdot \left(h \cdot D\right)\right)}\\
\mathbf{if}\;M \leq 1.35 \cdot 10^{-269}:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;M \leq 7 \cdot 10^{-157}:\\
\;\;\;\;c0 \cdot \frac{\mathsf{fma}\left(c0, t\_3, \sqrt{\mathsf{fma}\left(c0, t\_3, M\right) \cdot \left(c0 \cdot t\_3 - M\right)}\right)}{2 \cdot w}\\

\mathbf{elif}\;M \leq 1.4 \cdot 10^{-32}:\\
\;\;\;\;t\_2\\

\mathbf{else}:\\
\;\;\;\;\frac{c0}{2 \cdot w} \cdot \left(t\_1 + {\left(\left(M + c0 \cdot \frac{t\_0}{w \cdot h}\right) \cdot \left(t\_1 - M\right)\right)}^{0.5}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if M < 1.35000000000000008e-269 or 7.0000000000000004e-157 < M < 1.3999999999999999e-32

    1. Initial program 20.9%

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

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

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

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

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

      \[\leadsto c0 \cdot \color{blue}{\log \left({\left(e^{\frac{M}{2}}\right)}^{\left(\frac{\sqrt{-1}}{w}\right)}\right)} \]
    7. Taylor expanded in M around 0 32.1%

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

    if 1.35000000000000008e-269 < M < 7.0000000000000004e-157

    1. Initial program 46.9%

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

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

    if 1.3999999999999999e-32 < M

    1. Initial program 16.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. Simplified16.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;M \leq 1.35 \cdot 10^{-269}:\\ \;\;\;\;c0 \cdot \log \left({\left(1 + M \cdot 0.5\right)}^{\left(\frac{\sqrt{-1}}{w}\right)}\right)\\ \mathbf{elif}\;M \leq 7 \cdot 10^{-157}:\\ \;\;\;\;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}\\ \mathbf{elif}\;M \leq 1.4 \cdot 10^{-32}:\\ \;\;\;\;c0 \cdot \log \left({\left(1 + M \cdot 0.5\right)}^{\left(\frac{\sqrt{-1}}{w}\right)}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{c0}{2 \cdot w} \cdot \left(\frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2} + {\left(\left(M + c0 \cdot \frac{{\left(\frac{d}{D}\right)}^{2}}{w \cdot h}\right) \cdot \left(\frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2} - M\right)\right)}^{0.5}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 27.7% accurate, 0.4× speedup?

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

\\
\begin{array}{l}
t_0 := c0 \cdot \log \left({\left(1 + M \cdot 0.5\right)}^{\left(\frac{\sqrt{-1}}{w}\right)}\right)\\
t_1 := d \cdot \frac{d}{D \cdot \left(w \cdot \left(h \cdot D\right)\right)}\\
\mathbf{if}\;M \leq 4.6 \cdot 10^{-267}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;M \leq 2.15 \cdot 10^{-156}:\\
\;\;\;\;c0 \cdot \frac{\mathsf{fma}\left(c0, t\_1, \sqrt{\mathsf{fma}\left(c0, t\_1, M\right) \cdot \left(c0 \cdot t\_1 - M\right)}\right)}{2 \cdot w}\\

\mathbf{elif}\;M \leq 9 \cdot 10^{-32}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if M < 4.6000000000000001e-267 or 2.14999999999999989e-156 < M < 9.00000000000000009e-32

    1. Initial program 20.9%

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

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

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

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

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

      \[\leadsto c0 \cdot \color{blue}{\log \left({\left(e^{\frac{M}{2}}\right)}^{\left(\frac{\sqrt{-1}}{w}\right)}\right)} \]
    7. Taylor expanded in M around 0 32.1%

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

    if 4.6000000000000001e-267 < M < 2.14999999999999989e-156

    1. Initial program 46.9%

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

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

    if 9.00000000000000009e-32 < M

    1. Initial program 16.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. Simplified16.7%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;M \leq 4.6 \cdot 10^{-267}:\\ \;\;\;\;c0 \cdot \log \left({\left(1 + M \cdot 0.5\right)}^{\left(\frac{\sqrt{-1}}{w}\right)}\right)\\ \mathbf{elif}\;M \leq 2.15 \cdot 10^{-156}:\\ \;\;\;\;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}\\ \mathbf{elif}\;M \leq 9 \cdot 10^{-32}:\\ \;\;\;\;c0 \cdot \log \left({\left(1 + M \cdot 0.5\right)}^{\left(\frac{\sqrt{-1}}{w}\right)}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{c0}{2 \cdot w} \cdot \left(d \cdot \left(\frac{1}{D} \cdot \sqrt{\frac{c0 \cdot M}{w \cdot h}} + \frac{c0 \cdot d}{\left(w \cdot h\right) \cdot {D}^{2}}\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 27.6% accurate, 0.4× 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 := c0 \cdot \log \left({\left(1 + M \cdot 0.5\right)}^{\left(\frac{\sqrt{-1}}{w}\right)}\right)\\ \mathbf{if}\;M \leq 3 \cdot 10^{-269}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;M \leq 6.5 \cdot 10^{-156}:\\ \;\;\;\;c0 \cdot \frac{\mathsf{fma}\left(c0, d \cdot \frac{d}{D \cdot \left(D \cdot \left(w \cdot h\right)\right)}, \sqrt{\mathsf{fma}\left(c0, t\_0, M\right) \cdot \left(c0 \cdot t\_0 - M\right)}\right)}{2 \cdot w}\\ \mathbf{elif}\;M \leq 4.8 \cdot 10^{-33}:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;\frac{c0}{2 \cdot w} \cdot \left(d \cdot \left(\frac{1}{D} \cdot \sqrt{\frac{c0 \cdot M}{w \cdot h}} + \frac{c0 \cdot d}{\left(w \cdot h\right) \cdot {D}^{2}}\right)\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 (log (pow (+ 1.0 (* M 0.5)) (/ (sqrt -1.0) w))))))
   (if (<= M 3e-269)
     t_1
     (if (<= M 6.5e-156)
       (*
        c0
        (/
         (fma
          c0
          (* d (/ d (* D (* D (* w h)))))
          (sqrt (* (fma c0 t_0 M) (- (* c0 t_0) M))))
         (* 2.0 w)))
       (if (<= M 4.8e-33)
         t_1
         (*
          (/ c0 (* 2.0 w))
          (*
           d
           (+
            (* (/ 1.0 D) (sqrt (/ (* c0 M) (* w h))))
            (/ (* c0 d) (* (* w h) (pow D 2.0)))))))))))
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 * log(pow((1.0 + (M * 0.5)), (sqrt(-1.0) / w)));
	double tmp;
	if (M <= 3e-269) {
		tmp = t_1;
	} else if (M <= 6.5e-156) {
		tmp = c0 * (fma(c0, (d * (d / (D * (D * (w * h))))), sqrt((fma(c0, t_0, M) * ((c0 * t_0) - M)))) / (2.0 * w));
	} else if (M <= 4.8e-33) {
		tmp = t_1;
	} else {
		tmp = (c0 / (2.0 * w)) * (d * (((1.0 / D) * sqrt(((c0 * M) / (w * h)))) + ((c0 * d) / ((w * h) * pow(D, 2.0)))));
	}
	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(c0 * log((Float64(1.0 + Float64(M * 0.5)) ^ Float64(sqrt(-1.0) / w))))
	tmp = 0.0
	if (M <= 3e-269)
		tmp = t_1;
	elseif (M <= 6.5e-156)
		tmp = Float64(c0 * Float64(fma(c0, Float64(d * Float64(d / Float64(D * Float64(D * Float64(w * h))))), sqrt(Float64(fma(c0, t_0, M) * Float64(Float64(c0 * t_0) - M)))) / Float64(2.0 * w)));
	elseif (M <= 4.8e-33)
		tmp = t_1;
	else
		tmp = Float64(Float64(c0 / Float64(2.0 * w)) * Float64(d * Float64(Float64(Float64(1.0 / D) * sqrt(Float64(Float64(c0 * M) / Float64(w * h)))) + Float64(Float64(c0 * d) / Float64(Float64(w * h) * (D ^ 2.0))))));
	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[(c0 * N[Log[N[Power[N[(1.0 + N[(M * 0.5), $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[-1.0], $MachinePrecision] / w), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[M, 3e-269], t$95$1, If[LessEqual[M, 6.5e-156], N[(c0 * N[(N[(c0 * N[(d * N[(d / N[(D * N[(D * N[(w * h), $MachinePrecision]), $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[M, 4.8e-33], t$95$1, N[(N[(c0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision] * N[(d * N[(N[(N[(1.0 / D), $MachinePrecision] * N[Sqrt[N[(N[(c0 * M), $MachinePrecision] / N[(w * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + N[(N[(c0 * d), $MachinePrecision] / N[(N[(w * h), $MachinePrecision] * N[Power[D, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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 := c0 \cdot \log \left({\left(1 + M \cdot 0.5\right)}^{\left(\frac{\sqrt{-1}}{w}\right)}\right)\\
\mathbf{if}\;M \leq 3 \cdot 10^{-269}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;M \leq 6.5 \cdot 10^{-156}:\\
\;\;\;\;c0 \cdot \frac{\mathsf{fma}\left(c0, d \cdot \frac{d}{D \cdot \left(D \cdot \left(w \cdot h\right)\right)}, \sqrt{\mathsf{fma}\left(c0, t\_0, M\right) \cdot \left(c0 \cdot t\_0 - M\right)}\right)}{2 \cdot w}\\

\mathbf{elif}\;M \leq 4.8 \cdot 10^{-33}:\\
\;\;\;\;t\_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if M < 2.9999999999999999e-269 or 6.5000000000000002e-156 < M < 4.8e-33

    1. Initial program 20.9%

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

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

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

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

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

      \[\leadsto c0 \cdot \color{blue}{\log \left({\left(e^{\frac{M}{2}}\right)}^{\left(\frac{\sqrt{-1}}{w}\right)}\right)} \]
    7. Taylor expanded in M around 0 32.1%

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

    if 2.9999999999999999e-269 < M < 6.5000000000000002e-156

    1. Initial program 46.9%

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

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

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

    1. Initial program 16.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. Simplified16.7%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;M \leq 3 \cdot 10^{-269}:\\ \;\;\;\;c0 \cdot \log \left({\left(1 + M \cdot 0.5\right)}^{\left(\frac{\sqrt{-1}}{w}\right)}\right)\\ \mathbf{elif}\;M \leq 6.5 \cdot 10^{-156}:\\ \;\;\;\;c0 \cdot \frac{\mathsf{fma}\left(c0, d \cdot \frac{d}{D \cdot \left(D \cdot \left(w \cdot h\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}\\ \mathbf{elif}\;M \leq 4.8 \cdot 10^{-33}:\\ \;\;\;\;c0 \cdot \log \left({\left(1 + M \cdot 0.5\right)}^{\left(\frac{\sqrt{-1}}{w}\right)}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{c0}{2 \cdot w} \cdot \left(d \cdot \left(\frac{1}{D} \cdot \sqrt{\frac{c0 \cdot M}{w \cdot h}} + \frac{c0 \cdot d}{\left(w \cdot h\right) \cdot {D}^{2}}\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 27.1% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
t_0 := c0 \cdot \log \left({\left(1 + M \cdot 0.5\right)}^{\left(\frac{\sqrt{-1}}{w}\right)}\right)\\
t_1 := d \cdot \frac{d}{D \cdot \left(w \cdot \left(h \cdot D\right)\right)}\\
\mathbf{if}\;M \leq 4.8 \cdot 10^{-267}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;M \leq 3 \cdot 10^{-157}:\\
\;\;\;\;c0 \cdot \frac{\mathsf{fma}\left(c0, t\_1, \sqrt{M \cdot \left(c0 \cdot t\_1 - M\right)}\right)}{2 \cdot w}\\

\mathbf{elif}\;M \leq 2.3 \cdot 10^{-32}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if M < 4.7999999999999996e-267 or 3e-157 < M < 2.3000000000000001e-32

    1. Initial program 20.9%

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

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

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

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

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

      \[\leadsto c0 \cdot \color{blue}{\log \left({\left(e^{\frac{M}{2}}\right)}^{\left(\frac{\sqrt{-1}}{w}\right)}\right)} \]
    7. Taylor expanded in M around 0 32.1%

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

    if 4.7999999999999996e-267 < M < 3e-157

    1. Initial program 46.9%

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

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

    1. Initial program 16.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. Simplified16.7%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;M \leq 4.8 \cdot 10^{-267}:\\ \;\;\;\;c0 \cdot \log \left({\left(1 + M \cdot 0.5\right)}^{\left(\frac{\sqrt{-1}}{w}\right)}\right)\\ \mathbf{elif}\;M \leq 3 \cdot 10^{-157}:\\ \;\;\;\;c0 \cdot \frac{\mathsf{fma}\left(c0, d \cdot \frac{d}{D \cdot \left(w \cdot \left(h \cdot D\right)\right)}, \sqrt{M \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}\\ \mathbf{elif}\;M \leq 2.3 \cdot 10^{-32}:\\ \;\;\;\;c0 \cdot \log \left({\left(1 + M \cdot 0.5\right)}^{\left(\frac{\sqrt{-1}}{w}\right)}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{c0}{2 \cdot w} \cdot \left(d \cdot \left(\frac{1}{D} \cdot \sqrt{\frac{c0 \cdot M}{w \cdot h}} + \frac{c0 \cdot d}{\left(w \cdot h\right) \cdot {D}^{2}}\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 33.8% accurate, 0.5× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;t\_1 \cdot \frac{d \cdot \sqrt{M \cdot \frac{\frac{c0}{h}}{w}}}{D}\\


\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 67.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. Simplified68.3%

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

    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. Simplified0.7%

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

      \[\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{\frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2} - M}, \frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2}\right)} \]
    5. Taylor expanded in c0 around inf 14.8%

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

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

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

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

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

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \frac{d \cdot \sqrt{M \cdot \color{blue}{\frac{\frac{c0}{h}}{w}}}}{D} \]
    10. Applied egg-rr17.5%

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{\frac{d \cdot \sqrt{M \cdot \frac{\frac{c0}{h}}{w}}}{D}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification34.4%

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

Alternative 8: 14.3% accurate, 1.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;w \leq 1.6 \cdot 10^{+79}:\\
\;\;\;\;c0 \cdot \frac{\frac{d}{D} \cdot \sqrt{M \cdot \frac{c0}{w \cdot h}}}{2 \cdot w}\\

\mathbf{else}:\\
\;\;\;\;\frac{c0}{2 \cdot w} \cdot \frac{d \cdot \sqrt{M \cdot \frac{\frac{c0}{h}}{w}}}{D}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if w < 1.60000000000000001e79

    1. Initial program 24.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. Simplified25.0%

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

      \[\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{\frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2} - M}, \frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2}\right)} \]
    5. Taylor expanded in c0 around inf 22.1%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{c0 \cdot \frac{\frac{d}{D} \cdot \sqrt{M \cdot \frac{\frac{c0}{h}}{w}}}{2 \cdot w}} \]
      2. associate-/l/11.6%

        \[\leadsto c0 \cdot \frac{\frac{d}{D} \cdot \sqrt{M \cdot \color{blue}{\frac{c0}{w \cdot h}}}}{2 \cdot w} \]
      3. *-commutative11.6%

        \[\leadsto c0 \cdot \frac{\frac{d}{D} \cdot \sqrt{M \cdot \frac{c0}{\color{blue}{h \cdot w}}}}{2 \cdot w} \]
    12. Simplified11.6%

      \[\leadsto \color{blue}{c0 \cdot \frac{\frac{d}{D} \cdot \sqrt{M \cdot \frac{c0}{h \cdot w}}}{2 \cdot w}} \]

    if 1.60000000000000001e79 < w

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

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

      \[\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{\frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2} - M}, \frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2}\right)} \]
    5. Taylor expanded in c0 around inf 9.6%

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

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

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

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

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

        \[\leadsto \frac{c0}{2 \cdot w} \cdot \frac{d \cdot \sqrt{M \cdot \color{blue}{\frac{\frac{c0}{h}}{w}}}}{D} \]
    10. Applied egg-rr32.9%

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \color{blue}{\frac{d \cdot \sqrt{M \cdot \frac{\frac{c0}{h}}{w}}}{D}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification14.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;w \leq 1.6 \cdot 10^{+79}:\\ \;\;\;\;c0 \cdot \frac{\frac{d}{D} \cdot \sqrt{M \cdot \frac{c0}{w \cdot h}}}{2 \cdot w}\\ \mathbf{else}:\\ \;\;\;\;\frac{c0}{2 \cdot w} \cdot \frac{d \cdot \sqrt{M \cdot \frac{\frac{c0}{h}}{w}}}{D}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 13.6% accurate, 1.3× speedup?

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

\\
c0 \cdot \frac{\frac{d}{D} \cdot \sqrt{M \cdot \frac{c0}{w \cdot h}}}{2 \cdot w}
\end{array}
Derivation
  1. Initial program 22.4%

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

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

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

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

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

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(\frac{d}{D} \cdot \sqrt{\color{blue}{M \cdot \frac{c0}{h \cdot w}}}\right) \]
  8. Simplified12.3%

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

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

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

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

      \[\leadsto \color{blue}{c0 \cdot \frac{\frac{d}{D} \cdot \sqrt{M \cdot \frac{\frac{c0}{h}}{w}}}{2 \cdot w}} \]
    2. associate-/l/11.9%

      \[\leadsto c0 \cdot \frac{\frac{d}{D} \cdot \sqrt{M \cdot \color{blue}{\frac{c0}{w \cdot h}}}}{2 \cdot w} \]
    3. *-commutative11.9%

      \[\leadsto c0 \cdot \frac{\frac{d}{D} \cdot \sqrt{M \cdot \frac{c0}{\color{blue}{h \cdot w}}}}{2 \cdot w} \]
  12. Simplified11.9%

    \[\leadsto \color{blue}{c0 \cdot \frac{\frac{d}{D} \cdot \sqrt{M \cdot \frac{c0}{h \cdot w}}}{2 \cdot w}} \]
  13. Final simplification11.9%

    \[\leadsto c0 \cdot \frac{\frac{d}{D} \cdot \sqrt{M \cdot \frac{c0}{w \cdot h}}}{2 \cdot w} \]
  14. Add Preprocessing

Alternative 10: 0.0% accurate, 1.4× speedup?

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

\\
c0 \cdot \frac{M \cdot \sqrt{-1}}{2 \cdot w}
\end{array}
Derivation
  1. Initial program 22.4%

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

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

    \[\leadsto c0 \cdot \frac{\color{blue}{M \cdot \sqrt{-1}}}{2 \cdot w} \]
  5. Add Preprocessing

Reproduce

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