Henrywood and Agarwal, Equation (13)

Percentage Accurate: 24.5% → 52.8%
Time: 25.1s
Alternatives: 9
Speedup: 151.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 9 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: 52.8% accurate, 0.2× speedup?

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

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

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


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

      \[\leadsto \color{blue}{\frac{c0}{2 \cdot w} \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D} + \sqrt{\left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\right) \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\right) - M \cdot M}\right)} \]
    3. Add Preprocessing
    4. Applied egg-rr75.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 \cdot {\left(\frac{d}{D}\right)}^{2}}{w \cdot h} - M}, \frac{c0 \cdot {\left(\frac{d}{D}\right)}^{2}}{w \cdot h}\right)} \]
    5. Step-by-step derivation
      1. associate-/r*73.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if +inf.0 < (*.f64 (/.f64 c0 (*.f64 #s(literal 2 binary64) w)) (+.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (sqrt.f64 (-.f64 (*.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D)))) (*.f64 M M)))))

    1. Initial program 0.0%

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

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

      \[\leadsto \color{blue}{-0.5 \cdot \frac{M \cdot \left(c0 \cdot \sqrt{-1}\right)}{w}} \]
    5. Step-by-step derivation
      1. *-commutative0.0%

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

        \[\leadsto \frac{\color{blue}{\left(M \cdot c0\right) \cdot \sqrt{-1}}}{w} \cdot -0.5 \]
    6. Simplified0.0%

      \[\leadsto \color{blue}{\frac{\left(M \cdot c0\right) \cdot \sqrt{-1}}{w} \cdot -0.5} \]
    7. Step-by-step derivation
      1. add-log-exp0.0%

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

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

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

      \[\leadsto \frac{\color{blue}{\log \left({\left({\left(e^{M}\right)}^{c0}\right)}^{\left(\sqrt{-1}\right)}\right)}}{w} \cdot -0.5 \]
    9. Applied egg-rr36.8%

      \[\leadsto \frac{\log \color{blue}{\left(e^{M \cdot \left(c0 \cdot -1\right)}\right)}}{w} \cdot -0.5 \]
    10. Step-by-step derivation
      1. *-commutative36.8%

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

        \[\leadsto \frac{\log \left(e^{\color{blue}{c0 \cdot \left(-1 \cdot M\right)}}\right)}{w} \cdot -0.5 \]
      3. neg-mul-136.8%

        \[\leadsto \frac{\log \left(e^{c0 \cdot \color{blue}{\left(-M\right)}}\right)}{w} \cdot -0.5 \]
    11. Simplified36.8%

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

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

Alternative 2: 52.8% accurate, 0.4× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ \begin{array}{l} t_0 := \frac{c0}{2 \cdot w}\\ t_1 := \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}\\ \mathbf{if}\;t\_0 \cdot \left(t\_1 + \sqrt{t\_1 \cdot t\_1 - M\_m \cdot M\_m}\right) \leq \infty:\\ \;\;\;\;t\_0 \cdot \left(2 \cdot \frac{c0 \cdot \frac{{d}^{2}}{{D}^{2}}}{w \cdot h}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\log \left(e^{M\_m \cdot \left(-c0\right)}\right)}{w} \cdot -0.5\\ \end{array} \end{array} \]
M_m = (fabs.f64 M)
(FPCore (c0 w h D d M_m)
 :precision binary64
 (let* ((t_0 (/ c0 (* 2.0 w))) (t_1 (/ (* c0 (* d d)) (* (* w h) (* D D)))))
   (if (<= (* t_0 (+ t_1 (sqrt (- (* t_1 t_1) (* M_m M_m))))) INFINITY)
     (* t_0 (* 2.0 (/ (* c0 (/ (pow d 2.0) (pow D 2.0))) (* w h))))
     (* (/ (log (exp (* M_m (- c0)))) w) -0.5))))
M_m = fabs(M);
double code(double c0, double w, double h, double D, double d, double M_m) {
	double t_0 = c0 / (2.0 * w);
	double t_1 = (c0 * (d * d)) / ((w * h) * (D * D));
	double tmp;
	if ((t_0 * (t_1 + sqrt(((t_1 * t_1) - (M_m * M_m))))) <= ((double) INFINITY)) {
		tmp = t_0 * (2.0 * ((c0 * (pow(d, 2.0) / pow(D, 2.0))) / (w * h)));
	} else {
		tmp = (log(exp((M_m * -c0))) / w) * -0.5;
	}
	return tmp;
}
M_m = Math.abs(M);
public static double code(double c0, double w, double h, double D, double d, double M_m) {
	double t_0 = c0 / (2.0 * w);
	double t_1 = (c0 * (d * d)) / ((w * h) * (D * D));
	double tmp;
	if ((t_0 * (t_1 + Math.sqrt(((t_1 * t_1) - (M_m * M_m))))) <= Double.POSITIVE_INFINITY) {
		tmp = t_0 * (2.0 * ((c0 * (Math.pow(d, 2.0) / Math.pow(D, 2.0))) / (w * h)));
	} else {
		tmp = (Math.log(Math.exp((M_m * -c0))) / w) * -0.5;
	}
	return tmp;
}
M_m = math.fabs(M)
def code(c0, w, h, D, d, M_m):
	t_0 = c0 / (2.0 * w)
	t_1 = (c0 * (d * d)) / ((w * h) * (D * D))
	tmp = 0
	if (t_0 * (t_1 + math.sqrt(((t_1 * t_1) - (M_m * M_m))))) <= math.inf:
		tmp = t_0 * (2.0 * ((c0 * (math.pow(d, 2.0) / math.pow(D, 2.0))) / (w * h)))
	else:
		tmp = (math.log(math.exp((M_m * -c0))) / w) * -0.5
	return tmp
M_m = abs(M)
function code(c0, w, h, D, d, M_m)
	t_0 = Float64(c0 / Float64(2.0 * w))
	t_1 = Float64(Float64(c0 * Float64(d * d)) / Float64(Float64(w * h) * Float64(D * D)))
	tmp = 0.0
	if (Float64(t_0 * Float64(t_1 + sqrt(Float64(Float64(t_1 * t_1) - Float64(M_m * M_m))))) <= Inf)
		tmp = Float64(t_0 * Float64(2.0 * Float64(Float64(c0 * Float64((d ^ 2.0) / (D ^ 2.0))) / Float64(w * h))));
	else
		tmp = Float64(Float64(log(exp(Float64(M_m * Float64(-c0)))) / w) * -0.5);
	end
	return tmp
end
M_m = abs(M);
function tmp_2 = code(c0, w, h, D, d, M_m)
	t_0 = c0 / (2.0 * w);
	t_1 = (c0 * (d * d)) / ((w * h) * (D * D));
	tmp = 0.0;
	if ((t_0 * (t_1 + sqrt(((t_1 * t_1) - (M_m * M_m))))) <= Inf)
		tmp = t_0 * (2.0 * ((c0 * ((d ^ 2.0) / (D ^ 2.0))) / (w * h)));
	else
		tmp = (log(exp((M_m * -c0))) / w) * -0.5;
	end
	tmp_2 = tmp;
end
M_m = N[Abs[M], $MachinePrecision]
code[c0_, w_, h_, D_, d_, M$95$m_] := Block[{t$95$0 = N[(c0 / N[(2.0 * w), $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]}, If[LessEqual[N[(t$95$0 * N[(t$95$1 + N[Sqrt[N[(N[(t$95$1 * t$95$1), $MachinePrecision] - N[(M$95$m * M$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], Infinity], N[(t$95$0 * N[(2.0 * N[(N[(c0 * N[(N[Power[d, 2.0], $MachinePrecision] / N[Power[D, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(w * h), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Log[N[Exp[N[(M$95$m * (-c0)), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] / w), $MachinePrecision] * -0.5), $MachinePrecision]]]]
\begin{array}{l}
M_m = \left|M\right|

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if +inf.0 < (*.f64 (/.f64 c0 (*.f64 #s(literal 2 binary64) w)) (+.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (sqrt.f64 (-.f64 (*.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D)))) (*.f64 M M)))))

    1. Initial program 0.0%

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

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

      \[\leadsto \color{blue}{-0.5 \cdot \frac{M \cdot \left(c0 \cdot \sqrt{-1}\right)}{w}} \]
    5. Step-by-step derivation
      1. *-commutative0.0%

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

        \[\leadsto \frac{\color{blue}{\left(M \cdot c0\right) \cdot \sqrt{-1}}}{w} \cdot -0.5 \]
    6. Simplified0.0%

      \[\leadsto \color{blue}{\frac{\left(M \cdot c0\right) \cdot \sqrt{-1}}{w} \cdot -0.5} \]
    7. Step-by-step derivation
      1. add-log-exp0.0%

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

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

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

      \[\leadsto \frac{\color{blue}{\log \left({\left({\left(e^{M}\right)}^{c0}\right)}^{\left(\sqrt{-1}\right)}\right)}}{w} \cdot -0.5 \]
    9. Applied egg-rr36.8%

      \[\leadsto \frac{\log \color{blue}{\left(e^{M \cdot \left(c0 \cdot -1\right)}\right)}}{w} \cdot -0.5 \]
    10. Step-by-step derivation
      1. *-commutative36.8%

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

        \[\leadsto \frac{\log \left(e^{\color{blue}{c0 \cdot \left(-1 \cdot M\right)}}\right)}{w} \cdot -0.5 \]
      3. neg-mul-136.8%

        \[\leadsto \frac{\log \left(e^{c0 \cdot \color{blue}{\left(-M\right)}}\right)}{w} \cdot -0.5 \]
    11. Simplified36.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \leq \infty:\\ \;\;\;\;\frac{c0}{2 \cdot w} \cdot \left(2 \cdot \frac{c0 \cdot \frac{{d}^{2}}{{D}^{2}}}{w \cdot h}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\log \left(e^{M \cdot \left(-c0\right)}\right)}{w} \cdot -0.5\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 52.9% accurate, 0.4× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ \begin{array}{l} t_0 := \frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\\ t_1 := \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)}\\ \mathbf{if}\;\frac{c0}{2 \cdot w} \cdot \left(t\_1 + \sqrt{t\_1 \cdot t\_1 - M\_m \cdot M\_m}\right) \leq \infty:\\ \;\;\;\;\left(c0 \cdot \frac{1}{2 \cdot w}\right) \cdot \left(t\_0 + \sqrt{t\_0 \cdot t\_0 - M\_m \cdot M\_m}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\log \left(e^{M\_m \cdot \left(-c0\right)}\right)}{w} \cdot -0.5\\ \end{array} \end{array} \]
M_m = (fabs.f64 M)
(FPCore (c0 w h D d M_m)
 :precision binary64
 (let* ((t_0 (* (/ c0 (* w h)) (/ (* d d) (* D D))))
        (t_1 (/ (* c0 (* d d)) (* (* w h) (* D D)))))
   (if (<=
        (* (/ c0 (* 2.0 w)) (+ t_1 (sqrt (- (* t_1 t_1) (* M_m M_m)))))
        INFINITY)
     (* (* c0 (/ 1.0 (* 2.0 w))) (+ t_0 (sqrt (- (* t_0 t_0) (* M_m M_m)))))
     (* (/ (log (exp (* M_m (- c0)))) w) -0.5))))
M_m = fabs(M);
double code(double c0, double w, double h, double D, double d, double M_m) {
	double t_0 = (c0 / (w * h)) * ((d * d) / (D * D));
	double t_1 = (c0 * (d * d)) / ((w * h) * (D * D));
	double tmp;
	if (((c0 / (2.0 * w)) * (t_1 + sqrt(((t_1 * t_1) - (M_m * M_m))))) <= ((double) INFINITY)) {
		tmp = (c0 * (1.0 / (2.0 * w))) * (t_0 + sqrt(((t_0 * t_0) - (M_m * M_m))));
	} else {
		tmp = (log(exp((M_m * -c0))) / w) * -0.5;
	}
	return tmp;
}
M_m = Math.abs(M);
public static double code(double c0, double w, double h, double D, double d, double M_m) {
	double t_0 = (c0 / (w * h)) * ((d * d) / (D * D));
	double t_1 = (c0 * (d * d)) / ((w * h) * (D * D));
	double tmp;
	if (((c0 / (2.0 * w)) * (t_1 + Math.sqrt(((t_1 * t_1) - (M_m * M_m))))) <= Double.POSITIVE_INFINITY) {
		tmp = (c0 * (1.0 / (2.0 * w))) * (t_0 + Math.sqrt(((t_0 * t_0) - (M_m * M_m))));
	} else {
		tmp = (Math.log(Math.exp((M_m * -c0))) / w) * -0.5;
	}
	return tmp;
}
M_m = math.fabs(M)
def code(c0, w, h, D, d, M_m):
	t_0 = (c0 / (w * h)) * ((d * d) / (D * D))
	t_1 = (c0 * (d * d)) / ((w * h) * (D * D))
	tmp = 0
	if ((c0 / (2.0 * w)) * (t_1 + math.sqrt(((t_1 * t_1) - (M_m * M_m))))) <= math.inf:
		tmp = (c0 * (1.0 / (2.0 * w))) * (t_0 + math.sqrt(((t_0 * t_0) - (M_m * M_m))))
	else:
		tmp = (math.log(math.exp((M_m * -c0))) / w) * -0.5
	return tmp
M_m = abs(M)
function code(c0, w, h, D, d, M_m)
	t_0 = Float64(Float64(c0 / Float64(w * h)) * Float64(Float64(d * d) / Float64(D * D)))
	t_1 = Float64(Float64(c0 * Float64(d * d)) / Float64(Float64(w * h) * Float64(D * D)))
	tmp = 0.0
	if (Float64(Float64(c0 / Float64(2.0 * w)) * Float64(t_1 + sqrt(Float64(Float64(t_1 * t_1) - Float64(M_m * M_m))))) <= Inf)
		tmp = Float64(Float64(c0 * Float64(1.0 / Float64(2.0 * w))) * Float64(t_0 + sqrt(Float64(Float64(t_0 * t_0) - Float64(M_m * M_m)))));
	else
		tmp = Float64(Float64(log(exp(Float64(M_m * Float64(-c0)))) / w) * -0.5);
	end
	return tmp
end
M_m = abs(M);
function tmp_2 = code(c0, w, h, D, d, M_m)
	t_0 = (c0 / (w * h)) * ((d * d) / (D * D));
	t_1 = (c0 * (d * d)) / ((w * h) * (D * D));
	tmp = 0.0;
	if (((c0 / (2.0 * w)) * (t_1 + sqrt(((t_1 * t_1) - (M_m * M_m))))) <= Inf)
		tmp = (c0 * (1.0 / (2.0 * w))) * (t_0 + sqrt(((t_0 * t_0) - (M_m * M_m))));
	else
		tmp = (log(exp((M_m * -c0))) / w) * -0.5;
	end
	tmp_2 = tmp;
end
M_m = N[Abs[M], $MachinePrecision]
code[c0_, w_, h_, D_, d_, M$95$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[(N[(c0 * N[(d * d), $MachinePrecision]), $MachinePrecision] / N[(N[(w * h), $MachinePrecision] * N[(D * D), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[(c0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision] * N[(t$95$1 + N[Sqrt[N[(N[(t$95$1 * t$95$1), $MachinePrecision] - N[(M$95$m * M$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], Infinity], N[(N[(c0 * N[(1.0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(t$95$0 + N[Sqrt[N[(N[(t$95$0 * t$95$0), $MachinePrecision] - N[(M$95$m * M$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Log[N[Exp[N[(M$95$m * (-c0)), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] / w), $MachinePrecision] * -0.5), $MachinePrecision]]]]
\begin{array}{l}
M_m = \left|M\right|

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

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


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

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

        \[\leadsto \color{blue}{\left(c0 \cdot \frac{1}{2 \cdot w}\right)} \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) \]
      2. *-commutative71.6%

        \[\leadsto \left(c0 \cdot \frac{1}{\color{blue}{w \cdot 2}}\right) \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. Applied egg-rr71.6%

      \[\leadsto \color{blue}{\left(c0 \cdot \frac{1}{w \cdot 2}\right)} \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) \]

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

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

      \[\leadsto \color{blue}{-0.5 \cdot \frac{M \cdot \left(c0 \cdot \sqrt{-1}\right)}{w}} \]
    5. Step-by-step derivation
      1. *-commutative0.0%

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

        \[\leadsto \frac{\color{blue}{\left(M \cdot c0\right) \cdot \sqrt{-1}}}{w} \cdot -0.5 \]
    6. Simplified0.0%

      \[\leadsto \color{blue}{\frac{\left(M \cdot c0\right) \cdot \sqrt{-1}}{w} \cdot -0.5} \]
    7. Step-by-step derivation
      1. add-log-exp0.0%

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

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

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

      \[\leadsto \frac{\color{blue}{\log \left({\left({\left(e^{M}\right)}^{c0}\right)}^{\left(\sqrt{-1}\right)}\right)}}{w} \cdot -0.5 \]
    9. Applied egg-rr36.8%

      \[\leadsto \frac{\log \color{blue}{\left(e^{M \cdot \left(c0 \cdot -1\right)}\right)}}{w} \cdot -0.5 \]
    10. Step-by-step derivation
      1. *-commutative36.8%

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

        \[\leadsto \frac{\log \left(e^{\color{blue}{c0 \cdot \left(-1 \cdot M\right)}}\right)}{w} \cdot -0.5 \]
      3. neg-mul-136.8%

        \[\leadsto \frac{\log \left(e^{c0 \cdot \color{blue}{\left(-M\right)}}\right)}{w} \cdot -0.5 \]
    11. Simplified36.8%

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

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

Alternative 4: 53.0% accurate, 0.5× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;0\\


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

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

        \[\leadsto \color{blue}{\left(c0 \cdot \frac{1}{2 \cdot w}\right)} \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) \]
      2. *-commutative71.6%

        \[\leadsto \left(c0 \cdot \frac{1}{\color{blue}{w \cdot 2}}\right) \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. Applied egg-rr71.6%

      \[\leadsto \color{blue}{\left(c0 \cdot \frac{1}{w \cdot 2}\right)} \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) \]

    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. Simplified23.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. Step-by-step derivation
      1. fma-undefine24.3%

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

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

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

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

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

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

        \[\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. associate-*l/11.2%

        \[\leadsto c0 \cdot \frac{\color{blue}{\frac{c0 \cdot \frac{d \cdot d}{D \cdot D}}{w \cdot h}} + \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. times-frac19.3%

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

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

      \[\leadsto c0 \cdot \frac{\color{blue}{\frac{c0 \cdot {\left(\frac{d}{D}\right)}^{2}}{w \cdot h} + \sqrt{{\left(\frac{c0 \cdot {\left(\frac{d}{D}\right)}^{2}}{w \cdot h}\right)}^{2} - {M}^{2}}}}{2 \cdot w} \]
    6. Taylor expanded in c0 around -inf 0.0%

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

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

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

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

        \[\leadsto \frac{-0.5 \cdot \left({c0}^{2} \cdot \color{blue}{0}\right)}{w} \]
    8. Simplified32.3%

      \[\leadsto \color{blue}{\frac{-0.5 \cdot \left({c0}^{2} \cdot 0\right)}{w}} \]
    9. Taylor expanded in c0 around 0 41.5%

      \[\leadsto \color{blue}{0} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification50.9%

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

Alternative 5: 52.8% accurate, 0.5× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;0\\


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

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

        \[\leadsto \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 \color{blue}{\left(\frac{d}{D} \cdot \frac{d}{D}\right)}\right) - M \cdot M}\right) \]
    5. Applied egg-rr71.6%

      \[\leadsto \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 \color{blue}{\left(\frac{d}{D} \cdot \frac{d}{D}\right)}\right) - M \cdot M}\right) \]

    if +inf.0 < (*.f64 (/.f64 c0 (*.f64 #s(literal 2 binary64) w)) (+.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (sqrt.f64 (-.f64 (*.f64 (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D))) (/.f64 (*.f64 c0 (*.f64 d d)) (*.f64 (*.f64 w h) (*.f64 D D)))) (*.f64 M M)))))

    1. Initial program 0.0%

      \[\frac{c0}{2 \cdot w} \cdot \left(\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} + \sqrt{\frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(w \cdot h\right) \cdot \left(D \cdot D\right)} - M \cdot M}\right) \]
    2. Simplified23.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. Step-by-step derivation
      1. fma-undefine24.3%

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

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

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

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

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

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

        \[\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. associate-*l/11.2%

        \[\leadsto c0 \cdot \frac{\color{blue}{\frac{c0 \cdot \frac{d \cdot d}{D \cdot D}}{w \cdot h}} + \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. times-frac19.3%

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

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

      \[\leadsto c0 \cdot \frac{\color{blue}{\frac{c0 \cdot {\left(\frac{d}{D}\right)}^{2}}{w \cdot h} + \sqrt{{\left(\frac{c0 \cdot {\left(\frac{d}{D}\right)}^{2}}{w \cdot h}\right)}^{2} - {M}^{2}}}}{2 \cdot w} \]
    6. Taylor expanded in c0 around -inf 0.0%

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

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

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

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

        \[\leadsto \frac{-0.5 \cdot \left({c0}^{2} \cdot \color{blue}{0}\right)}{w} \]
    8. Simplified32.3%

      \[\leadsto \color{blue}{\frac{-0.5 \cdot \left({c0}^{2} \cdot 0\right)}{w}} \]
    9. Taylor expanded in c0 around 0 41.5%

      \[\leadsto \color{blue}{0} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 6: 36.8% accurate, 1.2× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ \begin{array}{l} \mathbf{if}\;c0 \leq -3 \cdot 10^{+213}:\\ \;\;\;\;0\\ \mathbf{elif}\;c0 \leq -7.5 \cdot 10^{+59}:\\ \;\;\;\;c0 \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(D \cdot D\right) \cdot \left(h \cdot {w}^{2}\right)}\\ \mathbf{elif}\;c0 \leq 4.9 \cdot 10^{-6}:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;{\left(w \cdot 0\right)}^{-1}\\ \end{array} \end{array} \]
M_m = (fabs.f64 M)
(FPCore (c0 w h D d M_m)
 :precision binary64
 (if (<= c0 -3e+213)
   0.0
   (if (<= c0 -7.5e+59)
     (* c0 (/ (* c0 (* d d)) (* (* D D) (* h (pow w 2.0)))))
     (if (<= c0 4.9e-6) 0.0 (pow (* w 0.0) -1.0)))))
M_m = fabs(M);
double code(double c0, double w, double h, double D, double d, double M_m) {
	double tmp;
	if (c0 <= -3e+213) {
		tmp = 0.0;
	} else if (c0 <= -7.5e+59) {
		tmp = c0 * ((c0 * (d * d)) / ((D * D) * (h * pow(w, 2.0))));
	} else if (c0 <= 4.9e-6) {
		tmp = 0.0;
	} else {
		tmp = pow((w * 0.0), -1.0);
	}
	return tmp;
}
M_m = abs(m)
real(8) function code(c0, w, h, d, d_1, m_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_m
    real(8) :: tmp
    if (c0 <= (-3d+213)) then
        tmp = 0.0d0
    else if (c0 <= (-7.5d+59)) then
        tmp = c0 * ((c0 * (d_1 * d_1)) / ((d * d) * (h * (w ** 2.0d0))))
    else if (c0 <= 4.9d-6) then
        tmp = 0.0d0
    else
        tmp = (w * 0.0d0) ** (-1.0d0)
    end if
    code = tmp
end function
M_m = Math.abs(M);
public static double code(double c0, double w, double h, double D, double d, double M_m) {
	double tmp;
	if (c0 <= -3e+213) {
		tmp = 0.0;
	} else if (c0 <= -7.5e+59) {
		tmp = c0 * ((c0 * (d * d)) / ((D * D) * (h * Math.pow(w, 2.0))));
	} else if (c0 <= 4.9e-6) {
		tmp = 0.0;
	} else {
		tmp = Math.pow((w * 0.0), -1.0);
	}
	return tmp;
}
M_m = math.fabs(M)
def code(c0, w, h, D, d, M_m):
	tmp = 0
	if c0 <= -3e+213:
		tmp = 0.0
	elif c0 <= -7.5e+59:
		tmp = c0 * ((c0 * (d * d)) / ((D * D) * (h * math.pow(w, 2.0))))
	elif c0 <= 4.9e-6:
		tmp = 0.0
	else:
		tmp = math.pow((w * 0.0), -1.0)
	return tmp
M_m = abs(M)
function code(c0, w, h, D, d, M_m)
	tmp = 0.0
	if (c0 <= -3e+213)
		tmp = 0.0;
	elseif (c0 <= -7.5e+59)
		tmp = Float64(c0 * Float64(Float64(c0 * Float64(d * d)) / Float64(Float64(D * D) * Float64(h * (w ^ 2.0)))));
	elseif (c0 <= 4.9e-6)
		tmp = 0.0;
	else
		tmp = Float64(w * 0.0) ^ -1.0;
	end
	return tmp
end
M_m = abs(M);
function tmp_2 = code(c0, w, h, D, d, M_m)
	tmp = 0.0;
	if (c0 <= -3e+213)
		tmp = 0.0;
	elseif (c0 <= -7.5e+59)
		tmp = c0 * ((c0 * (d * d)) / ((D * D) * (h * (w ^ 2.0))));
	elseif (c0 <= 4.9e-6)
		tmp = 0.0;
	else
		tmp = (w * 0.0) ^ -1.0;
	end
	tmp_2 = tmp;
end
M_m = N[Abs[M], $MachinePrecision]
code[c0_, w_, h_, D_, d_, M$95$m_] := If[LessEqual[c0, -3e+213], 0.0, If[LessEqual[c0, -7.5e+59], N[(c0 * N[(N[(c0 * N[(d * d), $MachinePrecision]), $MachinePrecision] / N[(N[(D * D), $MachinePrecision] * N[(h * N[Power[w, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c0, 4.9e-6], 0.0, N[Power[N[(w * 0.0), $MachinePrecision], -1.0], $MachinePrecision]]]]
\begin{array}{l}
M_m = \left|M\right|

\\
\begin{array}{l}
\mathbf{if}\;c0 \leq -3 \cdot 10^{+213}:\\
\;\;\;\;0\\

\mathbf{elif}\;c0 \leq -7.5 \cdot 10^{+59}:\\
\;\;\;\;c0 \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(D \cdot D\right) \cdot \left(h \cdot {w}^{2}\right)}\\

\mathbf{elif}\;c0 \leq 4.9 \cdot 10^{-6}:\\
\;\;\;\;0\\

\mathbf{else}:\\
\;\;\;\;{\left(w \cdot 0\right)}^{-1}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c0 < -3.0000000000000001e213 or -7.4999999999999996e59 < c0 < 4.89999999999999967e-6

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

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

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

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

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

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

        \[\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-times22.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. associate-*l/22.3%

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

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

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

      \[\leadsto c0 \cdot \frac{\color{blue}{\frac{c0 \cdot {\left(\frac{d}{D}\right)}^{2}}{w \cdot h} + \sqrt{{\left(\frac{c0 \cdot {\left(\frac{d}{D}\right)}^{2}}{w \cdot h}\right)}^{2} - {M}^{2}}}}{2 \cdot w} \]
    6. Taylor expanded in c0 around -inf 4.5%

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

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

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

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

        \[\leadsto \frac{-0.5 \cdot \left({c0}^{2} \cdot \color{blue}{0}\right)}{w} \]
    8. Simplified36.3%

      \[\leadsto \color{blue}{\frac{-0.5 \cdot \left({c0}^{2} \cdot 0\right)}{w}} \]
    9. Taylor expanded in c0 around 0 41.5%

      \[\leadsto \color{blue}{0} \]

    if -3.0000000000000001e213 < c0 < -7.4999999999999996e59

    1. Initial program 37.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. Simplified50.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 inf 48.4%

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

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

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

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

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

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

    if 4.89999999999999967e-6 < 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. Simplified41.6%

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

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

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

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

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

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

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

        \[\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. associate-*l/28.9%

        \[\leadsto c0 \cdot \frac{\color{blue}{\frac{c0 \cdot \frac{d \cdot d}{D \cdot D}}{w \cdot h}} + \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. times-frac35.0%

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

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

      \[\leadsto c0 \cdot \frac{\color{blue}{\frac{c0 \cdot {\left(\frac{d}{D}\right)}^{2}}{w \cdot h} + \sqrt{{\left(\frac{c0 \cdot {\left(\frac{d}{D}\right)}^{2}}{w \cdot h}\right)}^{2} - {M}^{2}}}}{2 \cdot w} \]
    6. Taylor expanded in c0 around -inf 0.2%

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

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

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

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

        \[\leadsto \frac{-0.5 \cdot \left({c0}^{2} \cdot \color{blue}{0}\right)}{w} \]
    8. Simplified12.1%

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

      \[\leadsto \color{blue}{{\left(0 \cdot w\right)}^{-1}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification41.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;c0 \leq -3 \cdot 10^{+213}:\\ \;\;\;\;0\\ \mathbf{elif}\;c0 \leq -7.5 \cdot 10^{+59}:\\ \;\;\;\;c0 \cdot \frac{c0 \cdot \left(d \cdot d\right)}{\left(D \cdot D\right) \cdot \left(h \cdot {w}^{2}\right)}\\ \mathbf{elif}\;c0 \leq 4.9 \cdot 10^{-6}:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;{\left(w \cdot 0\right)}^{-1}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 36.6% accurate, 1.4× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ \begin{array}{l} \mathbf{if}\;c0 \leq 0.00022:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;{\left(w \cdot 0\right)}^{-1}\\ \end{array} \end{array} \]
M_m = (fabs.f64 M)
(FPCore (c0 w h D d M_m)
 :precision binary64
 (if (<= c0 0.00022) 0.0 (pow (* w 0.0) -1.0)))
M_m = fabs(M);
double code(double c0, double w, double h, double D, double d, double M_m) {
	double tmp;
	if (c0 <= 0.00022) {
		tmp = 0.0;
	} else {
		tmp = pow((w * 0.0), -1.0);
	}
	return tmp;
}
M_m = abs(m)
real(8) function code(c0, w, h, d, d_1, m_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_m
    real(8) :: tmp
    if (c0 <= 0.00022d0) then
        tmp = 0.0d0
    else
        tmp = (w * 0.0d0) ** (-1.0d0)
    end if
    code = tmp
end function
M_m = Math.abs(M);
public static double code(double c0, double w, double h, double D, double d, double M_m) {
	double tmp;
	if (c0 <= 0.00022) {
		tmp = 0.0;
	} else {
		tmp = Math.pow((w * 0.0), -1.0);
	}
	return tmp;
}
M_m = math.fabs(M)
def code(c0, w, h, D, d, M_m):
	tmp = 0
	if c0 <= 0.00022:
		tmp = 0.0
	else:
		tmp = math.pow((w * 0.0), -1.0)
	return tmp
M_m = abs(M)
function code(c0, w, h, D, d, M_m)
	tmp = 0.0
	if (c0 <= 0.00022)
		tmp = 0.0;
	else
		tmp = Float64(w * 0.0) ^ -1.0;
	end
	return tmp
end
M_m = abs(M);
function tmp_2 = code(c0, w, h, D, d, M_m)
	tmp = 0.0;
	if (c0 <= 0.00022)
		tmp = 0.0;
	else
		tmp = (w * 0.0) ^ -1.0;
	end
	tmp_2 = tmp;
end
M_m = N[Abs[M], $MachinePrecision]
code[c0_, w_, h_, D_, d_, M$95$m_] := If[LessEqual[c0, 0.00022], 0.0, N[Power[N[(w * 0.0), $MachinePrecision], -1.0], $MachinePrecision]]
\begin{array}{l}
M_m = \left|M\right|

\\
\begin{array}{l}
\mathbf{if}\;c0 \leq 0.00022:\\
\;\;\;\;0\\

\mathbf{else}:\\
\;\;\;\;{\left(w \cdot 0\right)}^{-1}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c0 < 2.20000000000000008e-4

    1. Initial program 20.7%

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

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

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

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

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

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

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

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

        \[\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. associate-*l/27.5%

        \[\leadsto c0 \cdot \frac{\color{blue}{\frac{c0 \cdot \frac{d \cdot d}{D \cdot D}}{w \cdot h}} + \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. times-frac33.4%

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

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

      \[\leadsto c0 \cdot \frac{\color{blue}{\frac{c0 \cdot {\left(\frac{d}{D}\right)}^{2}}{w \cdot h} + \sqrt{{\left(\frac{c0 \cdot {\left(\frac{d}{D}\right)}^{2}}{w \cdot h}\right)}^{2} - {M}^{2}}}}{2 \cdot w} \]
    6. Taylor expanded in c0 around -inf 3.7%

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

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

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

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

        \[\leadsto \frac{-0.5 \cdot \left({c0}^{2} \cdot \color{blue}{0}\right)}{w} \]
    8. Simplified30.7%

      \[\leadsto \color{blue}{\frac{-0.5 \cdot \left({c0}^{2} \cdot 0\right)}{w}} \]
    9. Taylor expanded in c0 around 0 36.0%

      \[\leadsto \color{blue}{0} \]

    if 2.20000000000000008e-4 < 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. Simplified41.6%

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

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

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

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

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

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

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

        \[\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. associate-*l/28.9%

        \[\leadsto c0 \cdot \frac{\color{blue}{\frac{c0 \cdot \frac{d \cdot d}{D \cdot D}}{w \cdot h}} + \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. times-frac35.0%

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

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

      \[\leadsto c0 \cdot \frac{\color{blue}{\frac{c0 \cdot {\left(\frac{d}{D}\right)}^{2}}{w \cdot h} + \sqrt{{\left(\frac{c0 \cdot {\left(\frac{d}{D}\right)}^{2}}{w \cdot h}\right)}^{2} - {M}^{2}}}}{2 \cdot w} \]
    6. Taylor expanded in c0 around -inf 0.2%

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

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

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

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

        \[\leadsto \frac{-0.5 \cdot \left({c0}^{2} \cdot \color{blue}{0}\right)}{w} \]
    8. Simplified12.1%

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

      \[\leadsto \color{blue}{{\left(0 \cdot w\right)}^{-1}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification36.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;c0 \leq 0.00022:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;{\left(w \cdot 0\right)}^{-1}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 36.7% accurate, 11.6× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ \begin{array}{l} \mathbf{if}\;M\_m \leq 9 \cdot 10^{+136}:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{M\_m \cdot \left(-c0\right)}{w}\\ \end{array} \end{array} \]
M_m = (fabs.f64 M)
(FPCore (c0 w h D d M_m)
 :precision binary64
 (if (<= M_m 9e+136) 0.0 (* -0.5 (/ (* M_m (- c0)) w))))
M_m = fabs(M);
double code(double c0, double w, double h, double D, double d, double M_m) {
	double tmp;
	if (M_m <= 9e+136) {
		tmp = 0.0;
	} else {
		tmp = -0.5 * ((M_m * -c0) / w);
	}
	return tmp;
}
M_m = abs(m)
real(8) function code(c0, w, h, d, d_1, m_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_m
    real(8) :: tmp
    if (m_m <= 9d+136) then
        tmp = 0.0d0
    else
        tmp = (-0.5d0) * ((m_m * -c0) / w)
    end if
    code = tmp
end function
M_m = Math.abs(M);
public static double code(double c0, double w, double h, double D, double d, double M_m) {
	double tmp;
	if (M_m <= 9e+136) {
		tmp = 0.0;
	} else {
		tmp = -0.5 * ((M_m * -c0) / w);
	}
	return tmp;
}
M_m = math.fabs(M)
def code(c0, w, h, D, d, M_m):
	tmp = 0
	if M_m <= 9e+136:
		tmp = 0.0
	else:
		tmp = -0.5 * ((M_m * -c0) / w)
	return tmp
M_m = abs(M)
function code(c0, w, h, D, d, M_m)
	tmp = 0.0
	if (M_m <= 9e+136)
		tmp = 0.0;
	else
		tmp = Float64(-0.5 * Float64(Float64(M_m * Float64(-c0)) / w));
	end
	return tmp
end
M_m = abs(M);
function tmp_2 = code(c0, w, h, D, d, M_m)
	tmp = 0.0;
	if (M_m <= 9e+136)
		tmp = 0.0;
	else
		tmp = -0.5 * ((M_m * -c0) / w);
	end
	tmp_2 = tmp;
end
M_m = N[Abs[M], $MachinePrecision]
code[c0_, w_, h_, D_, d_, M$95$m_] := If[LessEqual[M$95$m, 9e+136], 0.0, N[(-0.5 * N[(N[(M$95$m * (-c0)), $MachinePrecision] / w), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
M_m = \left|M\right|

\\
\begin{array}{l}
\mathbf{if}\;M\_m \leq 9 \cdot 10^{+136}:\\
\;\;\;\;0\\

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


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

    1. Initial program 24.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. Simplified36.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
    4. Step-by-step derivation
      1. fma-undefine37.9%

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

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

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

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

        \[\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. associate-*l/27.4%

        \[\leadsto c0 \cdot \frac{\color{blue}{\frac{c0 \cdot \frac{d \cdot d}{D \cdot D}}{w \cdot h}} + \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. times-frac32.4%

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

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

      \[\leadsto c0 \cdot \frac{\color{blue}{\frac{c0 \cdot {\left(\frac{d}{D}\right)}^{2}}{w \cdot h} + \sqrt{{\left(\frac{c0 \cdot {\left(\frac{d}{D}\right)}^{2}}{w \cdot h}\right)}^{2} - {M}^{2}}}}{2 \cdot w} \]
    6. Taylor expanded in c0 around -inf 3.0%

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

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

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

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

        \[\leadsto \frac{-0.5 \cdot \left({c0}^{2} \cdot \color{blue}{0}\right)}{w} \]
    8. Simplified28.3%

      \[\leadsto \color{blue}{\frac{-0.5 \cdot \left({c0}^{2} \cdot 0\right)}{w}} \]
    9. Taylor expanded in c0 around 0 34.5%

      \[\leadsto \color{blue}{0} \]

    if 8.9999999999999999e136 < M

    1. Initial program 3.4%

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

      \[\leadsto \color{blue}{-0.5 \cdot \frac{M \cdot \left(c0 \cdot \sqrt{-1}\right)}{w}} \]
    5. Step-by-step derivation
      1. *-commutative0.0%

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

        \[\leadsto \frac{\color{blue}{\left(M \cdot c0\right) \cdot \sqrt{-1}}}{w} \cdot -0.5 \]
    6. Simplified0.0%

      \[\leadsto \color{blue}{\frac{\left(M \cdot c0\right) \cdot \sqrt{-1}}{w} \cdot -0.5} \]
    7. Step-by-step derivation
      1. add-log-exp0.0%

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

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

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

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

      \[\leadsto \frac{\color{blue}{\left(c0 \cdot M\right) \cdot -1}}{w} \cdot -0.5 \]
    10. Step-by-step derivation
      1. *-commutative36.1%

        \[\leadsto \frac{\color{blue}{-1 \cdot \left(c0 \cdot M\right)}}{w} \cdot -0.5 \]
      2. mul-1-neg36.1%

        \[\leadsto \frac{\color{blue}{-c0 \cdot M}}{w} \cdot -0.5 \]
      3. distribute-rgt-neg-in36.1%

        \[\leadsto \frac{\color{blue}{c0 \cdot \left(-M\right)}}{w} \cdot -0.5 \]
    11. Simplified36.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;M \leq 9 \cdot 10^{+136}:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{M \cdot \left(-c0\right)}{w}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 33.1% accurate, 151.0× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ 0 \end{array} \]
M_m = (fabs.f64 M)
(FPCore (c0 w h D d M_m) :precision binary64 0.0)
M_m = fabs(M);
double code(double c0, double w, double h, double D, double d, double M_m) {
	return 0.0;
}
M_m = abs(m)
real(8) function code(c0, w, h, d, d_1, m_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_m
    code = 0.0d0
end function
M_m = Math.abs(M);
public static double code(double c0, double w, double h, double D, double d, double M_m) {
	return 0.0;
}
M_m = math.fabs(M)
def code(c0, w, h, D, d, M_m):
	return 0.0
M_m = abs(M)
function code(c0, w, h, D, d, M_m)
	return 0.0
end
M_m = abs(M);
function tmp = code(c0, w, h, D, d, M_m)
	tmp = 0.0;
end
M_m = N[Abs[M], $MachinePrecision]
code[c0_, w_, h_, D_, d_, M$95$m_] := 0.0
\begin{array}{l}
M_m = \left|M\right|

\\
0
\end{array}
Derivation
  1. Initial program 21.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. 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. Step-by-step derivation
    1. fma-undefine38.8%

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

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

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

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

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

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

      \[\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. associate-*l/27.9%

      \[\leadsto c0 \cdot \frac{\color{blue}{\frac{c0 \cdot \frac{d \cdot d}{D \cdot D}}{w \cdot h}} + \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. times-frac33.9%

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

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

    \[\leadsto c0 \cdot \frac{\color{blue}{\frac{c0 \cdot {\left(\frac{d}{D}\right)}^{2}}{w \cdot h} + \sqrt{{\left(\frac{c0 \cdot {\left(\frac{d}{D}\right)}^{2}}{w \cdot h}\right)}^{2} - {M}^{2}}}}{2 \cdot w} \]
  6. Taylor expanded in c0 around -inf 2.7%

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

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

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

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

      \[\leadsto \frac{-0.5 \cdot \left({c0}^{2} \cdot \color{blue}{0}\right)}{w} \]
  8. Simplified25.6%

    \[\leadsto \color{blue}{\frac{-0.5 \cdot \left({c0}^{2} \cdot 0\right)}{w}} \]
  9. Taylor expanded in c0 around 0 32.0%

    \[\leadsto \color{blue}{0} \]
  10. Add Preprocessing

Reproduce

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