Henrywood and Agarwal, Equation (13)

Percentage Accurate: 24.4% → 41.9%
Time: 35.0s
Alternatives: 12
Speedup: 1.0×

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

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

Initial Program: 24.4% accurate, 1.0× speedup?

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

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

Alternative 1: 41.9% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := d \cdot \frac{d}{D \cdot \left(w \cdot \left(D \cdot h\right)\right)}\\ \mathbf{if}\;M \cdot M \leq 4 \cdot 10^{-172}:\\ \;\;\;\;c0 \cdot \log \left({\left(e^{M}\right)}^{\left(\frac{\sqrt{-1}}{w \cdot 2}\right)}\right)\\ \mathbf{else}:\\ \;\;\;\;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)}{w \cdot 2}\\ \end{array} \end{array} \]
(FPCore (c0 w h D d M)
 :precision binary64
 (let* ((t_0 (* d (/ d (* D (* w (* D h)))))))
   (if (<= (* M M) 4e-172)
     (* c0 (log (pow (exp M) (/ (sqrt -1.0) (* w 2.0)))))
     (*
      c0
      (/
       (fma
        c0
        (* d (/ d (* D (* D (* w h)))))
        (sqrt (* (fma c0 t_0 M) (- (* c0 t_0) M))))
       (* w 2.0))))))
double code(double c0, double w, double h, double D, double d, double M) {
	double t_0 = d * (d / (D * (w * (D * h))));
	double tmp;
	if ((M * M) <= 4e-172) {
		tmp = c0 * log(pow(exp(M), (sqrt(-1.0) / (w * 2.0))));
	} else {
		tmp = c0 * (fma(c0, (d * (d / (D * (D * (w * h))))), sqrt((fma(c0, t_0, M) * ((c0 * t_0) - M)))) / (w * 2.0));
	}
	return tmp;
}
function code(c0, w, h, D, d, M)
	t_0 = Float64(d * Float64(d / Float64(D * Float64(w * Float64(D * h)))))
	tmp = 0.0
	if (Float64(M * M) <= 4e-172)
		tmp = Float64(c0 * log((exp(M) ^ Float64(sqrt(-1.0) / Float64(w * 2.0)))));
	else
		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(w * 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[(D * h), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(M * M), $MachinePrecision], 4e-172], N[(c0 * N[Log[N[Power[N[Exp[M], $MachinePrecision], N[(N[Sqrt[-1.0], $MachinePrecision] / N[(w * 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 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[(w * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := d \cdot \frac{d}{D \cdot \left(w \cdot \left(D \cdot h\right)\right)}\\
\mathbf{if}\;M \cdot M \leq 4 \cdot 10^{-172}:\\
\;\;\;\;c0 \cdot \log \left({\left(e^{M}\right)}^{\left(\frac{\sqrt{-1}}{w \cdot 2}\right)}\right)\\

\mathbf{else}:\\
\;\;\;\;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)}{w \cdot 2}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 M M) < 4.0000000000000002e-172

    1. Initial program 24.8%

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

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

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

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

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

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

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

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

    if 4.0000000000000002e-172 < (*.f64 M M)

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

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

      \[\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} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification47.1%

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

Alternative 2: 38.9% accurate, 0.2× speedup?

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

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

\mathbf{elif}\;t\_2 \leq 0:\\
\;\;\;\;t\_0 \cdot \left(t\_3 + \sqrt{t\_3 \cdot t\_3 - M \cdot M}\right)\\

\mathbf{else}:\\
\;\;\;\;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\_4, M\right) \cdot \left(c0 \cdot t\_4 - M\right)}\right)}{w \cdot 2}\\


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

    1. Initial program 66.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. Simplified64.4%

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

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

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

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

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

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

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

    if -1.99999999999999987e-102 < (*.f64 (/.f64 c0 (*.f64 #s(literal 2 binary64) w)) (+.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (sqrt.f64 (-.f64 (*.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D)))) (*.f64 M M))))) < 0.0

    1. Initial program 63.1%

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

      \[\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 0.0 < (*.f64 (/.f64 c0 (*.f64 #s(literal 2 binary64) w)) (+.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (sqrt.f64 (-.f64 (*.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D)))) (*.f64 M M)))))

    1. Initial program 10.6%

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

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

      \[\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} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification39.9%

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

Alternative 3: 41.2% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := d \cdot \frac{d}{D \cdot \left(w \cdot \left(D \cdot h\right)\right)}\\ \mathbf{if}\;c0 \leq -1.3 \cdot 10^{-200} \lor \neg \left(c0 \leq 1.35 \cdot 10^{-45}\right):\\ \;\;\;\;c0 \cdot \frac{\mathsf{fma}\left(c0, t\_0, \sqrt{\mathsf{fma}\left(c0, t\_0, M\right) \cdot \left(c0 \cdot t\_0 - M\right)}\right)}{w \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\log \left({\left(e^{c0}\right)}^{\left(\frac{M}{2} \cdot \frac{\sqrt{-1}}{w}\right)}\right)\\ \end{array} \end{array} \]
(FPCore (c0 w h D d M)
 :precision binary64
 (let* ((t_0 (* d (/ d (* D (* w (* D h)))))))
   (if (or (<= c0 -1.3e-200) (not (<= c0 1.35e-45)))
     (*
      c0
      (/ (fma c0 t_0 (sqrt (* (fma c0 t_0 M) (- (* c0 t_0) M)))) (* w 2.0)))
     (log (pow (exp c0) (* (/ M 2.0) (/ (sqrt -1.0) w)))))))
double code(double c0, double w, double h, double D, double d, double M) {
	double t_0 = d * (d / (D * (w * (D * h))));
	double tmp;
	if ((c0 <= -1.3e-200) || !(c0 <= 1.35e-45)) {
		tmp = c0 * (fma(c0, t_0, sqrt((fma(c0, t_0, M) * ((c0 * t_0) - M)))) / (w * 2.0));
	} else {
		tmp = log(pow(exp(c0), ((M / 2.0) * (sqrt(-1.0) / w))));
	}
	return tmp;
}
function code(c0, w, h, D, d, M)
	t_0 = Float64(d * Float64(d / Float64(D * Float64(w * Float64(D * h)))))
	tmp = 0.0
	if ((c0 <= -1.3e-200) || !(c0 <= 1.35e-45))
		tmp = Float64(c0 * Float64(fma(c0, t_0, sqrt(Float64(fma(c0, t_0, M) * Float64(Float64(c0 * t_0) - M)))) / Float64(w * 2.0)));
	else
		tmp = log((exp(c0) ^ Float64(Float64(M / 2.0) * Float64(sqrt(-1.0) / w))));
	end
	return tmp
end
code[c0_, w_, h_, D_, d_, M_] := Block[{t$95$0 = N[(d * N[(d / N[(D * N[(w * N[(D * h), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[c0, -1.3e-200], N[Not[LessEqual[c0, 1.35e-45]], $MachinePrecision]], N[(c0 * N[(N[(c0 * t$95$0 + N[Sqrt[N[(N[(c0 * t$95$0 + M), $MachinePrecision] * N[(N[(c0 * t$95$0), $MachinePrecision] - M), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(w * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Log[N[Power[N[Exp[c0], $MachinePrecision], N[(N[(M / 2.0), $MachinePrecision] * N[(N[Sqrt[-1.0], $MachinePrecision] / w), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := d \cdot \frac{d}{D \cdot \left(w \cdot \left(D \cdot h\right)\right)}\\
\mathbf{if}\;c0 \leq -1.3 \cdot 10^{-200} \lor \neg \left(c0 \leq 1.35 \cdot 10^{-45}\right):\\
\;\;\;\;c0 \cdot \frac{\mathsf{fma}\left(c0, t\_0, \sqrt{\mathsf{fma}\left(c0, t\_0, M\right) \cdot \left(c0 \cdot t\_0 - M\right)}\right)}{w \cdot 2}\\

\mathbf{else}:\\
\;\;\;\;\log \left({\left(e^{c0}\right)}^{\left(\frac{M}{2} \cdot \frac{\sqrt{-1}}{w}\right)}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c0 < -1.29999999999999995e-200 or 1.34999999999999992e-45 < c0

    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. Simplified38.1%

      \[\leadsto \color{blue}{c0 \cdot \frac{\mathsf{fma}\left(c0, d \cdot \frac{d}{D \cdot \left(w \cdot \left(h \cdot D\right)\right)}, \sqrt{\mathsf{fma}\left(c0, d \cdot \frac{d}{D \cdot \left(w \cdot \left(h \cdot D\right)\right)}, M\right) \cdot \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.29999999999999995e-200 < c0 < 1.34999999999999992e-45

    1. Initial program 19.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. Simplified22.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 \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 \color{blue}{\log \left(e^{c0 \cdot \frac{M \cdot \sqrt{-1}}{2 \cdot w}}\right)} \]
      2. exp-prod55.6%

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

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

      \[\leadsto \color{blue}{\log \left({\left(e^{c0}\right)}^{\left(\frac{M}{2} \cdot \frac{\sqrt{-1}}{w}\right)}\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification42.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;c0 \leq -1.3 \cdot 10^{-200} \lor \neg \left(c0 \leq 1.35 \cdot 10^{-45}\right):\\ \;\;\;\;c0 \cdot \frac{\mathsf{fma}\left(c0, d \cdot \frac{d}{D \cdot \left(w \cdot \left(D \cdot h\right)\right)}, \sqrt{\mathsf{fma}\left(c0, d \cdot \frac{d}{D \cdot \left(w \cdot \left(D \cdot h\right)\right)}, M\right) \cdot \left(c0 \cdot \left(d \cdot \frac{d}{D \cdot \left(w \cdot \left(D \cdot h\right)\right)}\right) - M\right)}\right)}{w \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\log \left({\left(e^{c0}\right)}^{\left(\frac{M}{2} \cdot \frac{\sqrt{-1}}{w}\right)}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 27.2% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := d \cdot \frac{d}{D \cdot \left(w \cdot \left(D \cdot h\right)\right)}\\ t_1 := \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}\\ t_2 := \frac{c0}{w \cdot 2} \cdot \left(t\_1 + \sqrt{t\_1 \cdot t\_1 - M \cdot M}\right)\\ \mathbf{if}\;t\_2 \leq 4 \cdot 10^{+113}:\\ \;\;\;\;t\_2\\ \mathbf{else}:\\ \;\;\;\;c0 \cdot \frac{\mathsf{fma}\left(c0, t\_0, \sqrt{M \cdot \left(c0 \cdot t\_0 - M\right)}\right)}{w \cdot 2}\\ \end{array} \end{array} \]
(FPCore (c0 w h D d M)
 :precision binary64
 (let* ((t_0 (* d (/ d (* D (* w (* D h))))))
        (t_1 (/ (* c0 (* d d)) (* (* w h) (* D D))))
        (t_2 (* (/ c0 (* w 2.0)) (+ t_1 (sqrt (- (* t_1 t_1) (* M M)))))))
   (if (<= t_2 4e+113)
     t_2
     (* c0 (/ (fma c0 t_0 (sqrt (* M (- (* c0 t_0) M)))) (* w 2.0))))))
double code(double c0, double w, double h, double D, double d, double M) {
	double t_0 = d * (d / (D * (w * (D * h))));
	double t_1 = (c0 * (d * d)) / ((w * h) * (D * D));
	double t_2 = (c0 / (w * 2.0)) * (t_1 + sqrt(((t_1 * t_1) - (M * M))));
	double tmp;
	if (t_2 <= 4e+113) {
		tmp = t_2;
	} else {
		tmp = c0 * (fma(c0, t_0, sqrt((M * ((c0 * t_0) - M)))) / (w * 2.0));
	}
	return tmp;
}
function code(c0, w, h, D, d, M)
	t_0 = Float64(d * Float64(d / Float64(D * Float64(w * Float64(D * h)))))
	t_1 = Float64(Float64(c0 * Float64(d * d)) / Float64(Float64(w * h) * Float64(D * D)))
	t_2 = Float64(Float64(c0 / Float64(w * 2.0)) * Float64(t_1 + sqrt(Float64(Float64(t_1 * t_1) - Float64(M * M)))))
	tmp = 0.0
	if (t_2 <= 4e+113)
		tmp = t_2;
	else
		tmp = Float64(c0 * Float64(fma(c0, t_0, sqrt(Float64(M * Float64(Float64(c0 * t_0) - M)))) / Float64(w * 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[(D * h), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(c0 * N[(d * d), $MachinePrecision]), $MachinePrecision] / N[(N[(w * h), $MachinePrecision] * N[(D * D), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(c0 / N[(w * 2.0), $MachinePrecision]), $MachinePrecision] * N[(t$95$1 + N[Sqrt[N[(N[(t$95$1 * t$95$1), $MachinePrecision] - N[(M * M), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, 4e+113], t$95$2, N[(c0 * N[(N[(c0 * t$95$0 + N[Sqrt[N[(M * N[(N[(c0 * t$95$0), $MachinePrecision] - M), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(w * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

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

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


\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))))) < 4e113

    1. Initial program 67.0%

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

    if 4e113 < (*.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 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. Simplified29.3%

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

      \[\leadsto c0 \cdot \frac{\mathsf{fma}\left(c0, d \cdot \frac{d}{D \cdot \left(w \cdot \left(h \cdot D\right)\right)}, \sqrt{\color{blue}{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} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification28.9%

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

Alternative 5: 31.1% accurate, 0.4× speedup?

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

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

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


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

    1. Initial program 69.1%

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

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

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

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

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

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

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

Alternative 6: 38.3% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := d \cdot \frac{d}{D \cdot \left(w \cdot \left(D \cdot h\right)\right)}\\ c0 \cdot \frac{\mathsf{fma}\left(c0, t\_0, \sqrt{\mathsf{fma}\left(c0, t\_0, M\right) \cdot \left(c0 \cdot t\_0 - M\right)}\right)}{w \cdot 2} \end{array} \end{array} \]
(FPCore (c0 w h D d M)
 :precision binary64
 (let* ((t_0 (* d (/ d (* D (* w (* D h)))))))
   (*
    c0
    (/ (fma c0 t_0 (sqrt (* (fma c0 t_0 M) (- (* c0 t_0) M)))) (* w 2.0)))))
double code(double c0, double w, double h, double D, double d, double M) {
	double t_0 = d * (d / (D * (w * (D * h))));
	return c0 * (fma(c0, t_0, sqrt((fma(c0, t_0, M) * ((c0 * t_0) - M)))) / (w * 2.0));
}
function code(c0, w, h, D, d, M)
	t_0 = Float64(d * Float64(d / Float64(D * Float64(w * Float64(D * h)))))
	return Float64(c0 * Float64(fma(c0, t_0, sqrt(Float64(fma(c0, t_0, M) * Float64(Float64(c0 * t_0) - M)))) / Float64(w * 2.0)))
end
code[c0_, w_, h_, D_, d_, M_] := Block[{t$95$0 = N[(d * N[(d / N[(D * N[(w * N[(D * h), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(c0 * N[(N[(c0 * t$95$0 + N[Sqrt[N[(N[(c0 * t$95$0 + M), $MachinePrecision] * N[(N[(c0 * t$95$0), $MachinePrecision] - M), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(w * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := d \cdot \frac{d}{D \cdot \left(w \cdot \left(D \cdot h\right)\right)}\\
c0 \cdot \frac{\mathsf{fma}\left(c0, t\_0, \sqrt{\mathsf{fma}\left(c0, t\_0, M\right) \cdot \left(c0 \cdot t\_0 - M\right)}\right)}{w \cdot 2}
\end{array}
\end{array}
Derivation
  1. Initial program 22.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. Simplified37.2%

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

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

Alternative 7: 22.7% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;M \leq 5.8 \cdot 10^{-171}:\\
\;\;\;\;c0 \cdot \frac{\mathsf{fma}\left(c0, d \cdot \frac{d}{D \cdot \left(w \cdot \left(D \cdot h\right)\right)}, \sqrt{M \cdot \left(-M\right)}\right)}{w \cdot 2}\\

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


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

    1. Initial program 22.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. Simplified30.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 \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 8.1%

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

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

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

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

    if 5.7999999999999997e-171 < M

    1. Initial program 23.0%

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

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

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

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

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

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

Alternative 8: 31.8% accurate, 0.7× speedup?

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

\\
c0 \cdot \frac{1}{w \cdot \left(\frac{{D}^{2}}{c0} \cdot \frac{w \cdot h}{{d}^{2}}\right)}
\end{array}
Derivation
  1. Initial program 22.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. Applied egg-rr27.4%

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

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

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

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

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

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

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

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

    \[\leadsto c0 \cdot \frac{1}{w \cdot \left(\frac{{D}^{2}}{c0} \cdot \frac{w \cdot h}{{d}^{2}}\right)} \]
  11. Add Preprocessing

Alternative 9: 24.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}\\ \frac{c0}{w \cdot 2} \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 (* w 2.0)) (+ 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 / (w * 2.0)) * (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 / (w * 2.0d0)) * (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 / (w * 2.0)) * (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 / (w * 2.0)) * (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(w * 2.0)) * 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 / (w * 2.0)) * (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[(w * 2.0), $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}{w \cdot 2} \cdot \left(t\_0 + \sqrt{t\_0 \cdot t\_0 - M \cdot M}\right)
\end{array}
\end{array}
Derivation
  1. Initial program 22.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. Add Preprocessing
  3. Final simplification22.9%

    \[\leadsto \frac{c0}{w \cdot 2} \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) \]
  4. Add Preprocessing

Alternative 10: 24.6% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\\ \frac{c0}{w \cdot 2} \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 (* w h)) (/ (* d d) (* D D)))))
   (* (/ c0 (* w 2.0)) (+ 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 / (w * h)) * ((d * d) / (D * D));
	return (c0 / (w * 2.0)) * (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 / (w * h)) * ((d_1 * d_1) / (d * d))
    code = (c0 / (w * 2.0d0)) * (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 / (w * h)) * ((d * d) / (D * D));
	return (c0 / (w * 2.0)) * (t_0 + Math.sqrt(((t_0 * t_0) - (M * M))));
}
def code(c0, w, h, D, d, M):
	t_0 = (c0 / (w * h)) * ((d * d) / (D * D))
	return (c0 / (w * 2.0)) * (t_0 + math.sqrt(((t_0 * t_0) - (M * M))))
function code(c0, w, h, D, d, M)
	t_0 = Float64(Float64(c0 / Float64(w * h)) * Float64(Float64(d * d) / Float64(D * D)))
	return Float64(Float64(c0 / Float64(w * 2.0)) * 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 / (w * h)) * ((d * d) / (D * D));
	tmp = (c0 / (w * 2.0)) * (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[(w * h), $MachinePrecision]), $MachinePrecision] * N[(N[(d * d), $MachinePrecision] / N[(D * D), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(N[(c0 / N[(w * 2.0), $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}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\\
\frac{c0}{w \cdot 2} \cdot \left(t\_0 + \sqrt{t\_0 \cdot t\_0 - M \cdot M}\right)
\end{array}
\end{array}
Derivation
  1. Initial program 22.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. Simplified21.4%

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

    \[\leadsto \frac{c0}{w \cdot 2} \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) \]
  5. Add Preprocessing

Alternative 11: 24.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{c0}{w \cdot h}\\ t_1 := t\_0 \cdot \frac{d \cdot d}{D \cdot D}\\ \frac{c0}{w \cdot 2} \cdot \left(\sqrt{t\_1 \cdot t\_1 - M \cdot M} + t\_0 \cdot \left(\frac{d}{D} \cdot \frac{d}{D}\right)\right) \end{array} \end{array} \]
(FPCore (c0 w h D d M)
 :precision binary64
 (let* ((t_0 (/ c0 (* w h))) (t_1 (* t_0 (/ (* d d) (* D D)))))
   (*
    (/ c0 (* w 2.0))
    (+ (sqrt (- (* t_1 t_1) (* M M))) (* t_0 (* (/ d D) (/ d D)))))))
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 * ((d * d) / (D * D));
	return (c0 / (w * 2.0)) * (sqrt(((t_1 * t_1) - (M * M))) + (t_0 * ((d / D) * (d / D))));
}
real(8) function code(c0, w, h, d, d_1, m)
    real(8), intent (in) :: c0
    real(8), intent (in) :: w
    real(8), intent (in) :: h
    real(8), intent (in) :: d
    real(8), intent (in) :: d_1
    real(8), intent (in) :: m
    real(8) :: t_0
    real(8) :: t_1
    t_0 = c0 / (w * h)
    t_1 = t_0 * ((d_1 * d_1) / (d * d))
    code = (c0 / (w * 2.0d0)) * (sqrt(((t_1 * t_1) - (m * m))) + (t_0 * ((d_1 / d) * (d_1 / d))))
end function
public static 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 * ((d * d) / (D * D));
	return (c0 / (w * 2.0)) * (Math.sqrt(((t_1 * t_1) - (M * M))) + (t_0 * ((d / D) * (d / D))));
}
def code(c0, w, h, D, d, M):
	t_0 = c0 / (w * h)
	t_1 = t_0 * ((d * d) / (D * D))
	return (c0 / (w * 2.0)) * (math.sqrt(((t_1 * t_1) - (M * M))) + (t_0 * ((d / D) * (d / D))))
function code(c0, w, h, D, d, M)
	t_0 = Float64(c0 / Float64(w * h))
	t_1 = Float64(t_0 * Float64(Float64(d * d) / Float64(D * D)))
	return Float64(Float64(c0 / Float64(w * 2.0)) * Float64(sqrt(Float64(Float64(t_1 * t_1) - Float64(M * M))) + Float64(t_0 * Float64(Float64(d / D) * Float64(d / D)))))
end
function tmp = code(c0, w, h, D, d, M)
	t_0 = c0 / (w * h);
	t_1 = t_0 * ((d * d) / (D * D));
	tmp = (c0 / (w * 2.0)) * (sqrt(((t_1 * t_1) - (M * M))) + (t_0 * ((d / D) * (d / D))));
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[(N[(d * d), $MachinePrecision] / N[(D * D), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(N[(c0 / N[(w * 2.0), $MachinePrecision]), $MachinePrecision] * N[(N[Sqrt[N[(N[(t$95$1 * t$95$1), $MachinePrecision] - N[(M * M), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + N[(t$95$0 * N[(N[(d / D), $MachinePrecision] * N[(d / D), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{c0}{w \cdot h}\\
t_1 := t\_0 \cdot \frac{d \cdot d}{D \cdot D}\\
\frac{c0}{w \cdot 2} \cdot \left(\sqrt{t\_1 \cdot t\_1 - M \cdot M} + t\_0 \cdot \left(\frac{d}{D} \cdot \frac{d}{D}\right)\right)
\end{array}
\end{array}
Derivation
  1. Initial program 22.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. Simplified21.4%

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

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

    \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(\frac{c0}{w \cdot h} \cdot \color{blue}{\left(\frac{d}{D} \cdot \frac{d}{D}\right)} + \sqrt{\left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\right) \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\right) - M \cdot M}\right) \]
  6. Final simplification20.4%

    \[\leadsto \frac{c0}{w \cdot 2} \cdot \left(\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} + \frac{c0}{w \cdot h} \cdot \left(\frac{d}{D} \cdot \frac{d}{D}\right)\right) \]
  7. Add Preprocessing

Alternative 12: 0.0% accurate, 1.4× speedup?

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

\\
c0 \cdot \frac{M \cdot \sqrt{-1}}{w \cdot 2}
\end{array}
Derivation
  1. Initial program 22.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. Final simplification0.0%

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

Reproduce

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