Henrywood and Agarwal, Equation (13)

Percentage Accurate: 24.6% → 55.8%
Time: 35.0s
Alternatives: 11
Speedup: 21.6×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 11 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.6% 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: 55.8% accurate, 0.2× speedup?

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

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

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


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

    1. Initial program 69.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. Simplified70.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 55.3% accurate, 0.2× speedup?

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

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

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


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

    1. Initial program 69.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. Simplified70.8%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \mathsf{fma}\left(\color{blue}{0.5 \cdot \left(\frac{D \cdot M}{d} \cdot \sqrt{\frac{h \cdot w}{c0}}\right) + \frac{d}{D} \cdot \sqrt{\frac{c0}{h \cdot w}}}, \frac{d}{D} \cdot \sqrt{\frac{c0}{h \cdot w}}, {\left(\frac{d}{D} \cdot \sqrt{\frac{\frac{c0}{w}}{h}}\right)}^{2}\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. Simplified21.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. Taylor expanded in c0 around -inf 3.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 54.2% accurate, 0.2× speedup?

\[\begin{array}{l} D_m = \left|D\right| \\ d_m = \left|d\right| \\ M_m = \left|M\right| \\ \begin{array}{l} t_0 := \frac{c0}{w \cdot h}\\ t_1 := {\left(\frac{d\_m}{D\_m}\right)}^{2}\\ t_2 := \frac{c0}{2 \cdot w}\\ t_3 := \frac{c0 \cdot \left(d\_m \cdot d\_m\right)}{\left(D\_m \cdot D\_m\right) \cdot \left(w \cdot h\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)}, \frac{d\_m}{D\_m} \cdot \sqrt{t\_0}, t\_0 \cdot t\_1\right)\\ \mathbf{else}:\\ \;\;\;\;c0 \cdot \frac{0}{2 \cdot w}\\ \end{array} \end{array} \]
D_m = (fabs.f64 D)
d_m = (fabs.f64 d)
M_m = (fabs.f64 M)
(FPCore (c0 w h D_m d_m M_m)
 :precision binary64
 (let* ((t_0 (/ c0 (* w h)))
        (t_1 (pow (/ d_m D_m) 2.0))
        (t_2 (/ c0 (* 2.0 w)))
        (t_3 (/ (* c0 (* d_m d_m)) (* (* D_m D_m) (* w h)))))
   (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)) (* (/ d_m D_m) (sqrt t_0)) (* t_0 t_1)))
     (* c0 (/ 0.0 (* 2.0 w))))))
D_m = fabs(D);
d_m = fabs(d);
M_m = fabs(M);
double code(double c0, double w, double h, double D_m, double d_m, double M_m) {
	double t_0 = c0 / (w * h);
	double t_1 = pow((d_m / D_m), 2.0);
	double t_2 = c0 / (2.0 * w);
	double t_3 = (c0 * (d_m * d_m)) / ((D_m * D_m) * (w * h));
	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)), ((d_m / D_m) * sqrt(t_0)), (t_0 * t_1));
	} else {
		tmp = c0 * (0.0 / (2.0 * w));
	}
	return tmp;
}
D_m = abs(D)
d_m = abs(d)
M_m = abs(M)
function code(c0, w, h, D_m, d_m, M_m)
	t_0 = Float64(c0 / Float64(w * h))
	t_1 = Float64(d_m / D_m) ^ 2.0
	t_2 = Float64(c0 / Float64(2.0 * w))
	t_3 = Float64(Float64(c0 * Float64(d_m * d_m)) / Float64(Float64(D_m * D_m) * Float64(w * h)))
	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)), Float64(Float64(d_m / D_m) * sqrt(t_0)), Float64(t_0 * t_1)));
	else
		tmp = Float64(c0 * Float64(0.0 / Float64(2.0 * w)));
	end
	return tmp
end
D_m = N[Abs[D], $MachinePrecision]
d_m = N[Abs[d], $MachinePrecision]
M_m = N[Abs[M], $MachinePrecision]
code[c0_, w_, h_, D$95$m_, d$95$m_, M$95$m_] := Block[{t$95$0 = N[(c0 / N[(w * h), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Power[N[(d$95$m / D$95$m), $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$95$m * d$95$m), $MachinePrecision]), $MachinePrecision] / N[(N[(D$95$m * D$95$m), $MachinePrecision] * N[(w * h), $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[(N[(d$95$m / D$95$m), $MachinePrecision] * N[Sqrt[t$95$0], $MachinePrecision]), $MachinePrecision] + N[(t$95$0 * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(c0 * N[(0.0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
D_m = \left|D\right|
\\
d_m = \left|d\right|
\\
M_m = \left|M\right|

\\
\begin{array}{l}
t_0 := \frac{c0}{w \cdot h}\\
t_1 := {\left(\frac{d\_m}{D\_m}\right)}^{2}\\
t_2 := \frac{c0}{2 \cdot w}\\
t_3 := \frac{c0 \cdot \left(d\_m \cdot d\_m\right)}{\left(D\_m \cdot D\_m\right) \cdot \left(w \cdot h\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)}, \frac{d\_m}{D\_m} \cdot \sqrt{t\_0}, t\_0 \cdot t\_1\right)\\

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


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

    1. Initial program 69.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. Simplified70.8%

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

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

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

    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. Simplified21.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. Taylor expanded in c0 around -inf 3.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 54.0% accurate, 0.2× speedup?

\[\begin{array}{l} D_m = \left|D\right| \\ d_m = \left|d\right| \\ M_m = \left|M\right| \\ \begin{array}{l} t_0 := \frac{c0}{w \cdot h}\\ t_1 := \frac{d\_m}{D\_m} \cdot \sqrt{t\_0}\\ t_2 := \frac{c0}{2 \cdot w}\\ t_3 := \frac{c0 \cdot \left(d\_m \cdot d\_m\right)}{\left(D\_m \cdot D\_m\right) \cdot \left(w \cdot h\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(t\_1 + 0.5 \cdot \left(\frac{D\_m \cdot M\_m}{d\_m} \cdot \sqrt{\frac{w \cdot h}{c0}}\right), t\_1, t\_0 \cdot {\left(\frac{d\_m}{D\_m}\right)}^{2}\right)\\ \mathbf{else}:\\ \;\;\;\;c0 \cdot \frac{0}{2 \cdot w}\\ \end{array} \end{array} \]
D_m = (fabs.f64 D)
d_m = (fabs.f64 d)
M_m = (fabs.f64 M)
(FPCore (c0 w h D_m d_m M_m)
 :precision binary64
 (let* ((t_0 (/ c0 (* w h)))
        (t_1 (* (/ d_m D_m) (sqrt t_0)))
        (t_2 (/ c0 (* 2.0 w)))
        (t_3 (/ (* c0 (* d_m d_m)) (* (* D_m D_m) (* w h)))))
   (if (<= (* t_2 (+ t_3 (sqrt (- (* t_3 t_3) (* M_m M_m))))) INFINITY)
     (*
      t_2
      (fma
       (+ t_1 (* 0.5 (* (/ (* D_m M_m) d_m) (sqrt (/ (* w h) c0)))))
       t_1
       (* t_0 (pow (/ d_m D_m) 2.0))))
     (* c0 (/ 0.0 (* 2.0 w))))))
D_m = fabs(D);
d_m = fabs(d);
M_m = fabs(M);
double code(double c0, double w, double h, double D_m, double d_m, double M_m) {
	double t_0 = c0 / (w * h);
	double t_1 = (d_m / D_m) * sqrt(t_0);
	double t_2 = c0 / (2.0 * w);
	double t_3 = (c0 * (d_m * d_m)) / ((D_m * D_m) * (w * h));
	double tmp;
	if ((t_2 * (t_3 + sqrt(((t_3 * t_3) - (M_m * M_m))))) <= ((double) INFINITY)) {
		tmp = t_2 * fma((t_1 + (0.5 * (((D_m * M_m) / d_m) * sqrt(((w * h) / c0))))), t_1, (t_0 * pow((d_m / D_m), 2.0)));
	} else {
		tmp = c0 * (0.0 / (2.0 * w));
	}
	return tmp;
}
D_m = abs(D)
d_m = abs(d)
M_m = abs(M)
function code(c0, w, h, D_m, d_m, M_m)
	t_0 = Float64(c0 / Float64(w * h))
	t_1 = Float64(Float64(d_m / D_m) * sqrt(t_0))
	t_2 = Float64(c0 / Float64(2.0 * w))
	t_3 = Float64(Float64(c0 * Float64(d_m * d_m)) / Float64(Float64(D_m * D_m) * Float64(w * h)))
	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(Float64(t_1 + Float64(0.5 * Float64(Float64(Float64(D_m * M_m) / d_m) * sqrt(Float64(Float64(w * h) / c0))))), t_1, Float64(t_0 * (Float64(d_m / D_m) ^ 2.0))));
	else
		tmp = Float64(c0 * Float64(0.0 / Float64(2.0 * w)));
	end
	return tmp
end
D_m = N[Abs[D], $MachinePrecision]
d_m = N[Abs[d], $MachinePrecision]
M_m = N[Abs[M], $MachinePrecision]
code[c0_, w_, h_, D$95$m_, d$95$m_, M$95$m_] := Block[{t$95$0 = N[(c0 / N[(w * h), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(d$95$m / D$95$m), $MachinePrecision] * N[Sqrt[t$95$0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(c0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(N[(c0 * N[(d$95$m * d$95$m), $MachinePrecision]), $MachinePrecision] / N[(N[(D$95$m * D$95$m), $MachinePrecision] * N[(w * h), $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[(t$95$1 + N[(0.5 * N[(N[(N[(D$95$m * M$95$m), $MachinePrecision] / d$95$m), $MachinePrecision] * N[Sqrt[N[(N[(w * h), $MachinePrecision] / c0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * t$95$1 + N[(t$95$0 * N[Power[N[(d$95$m / D$95$m), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(c0 * N[(0.0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
D_m = \left|D\right|
\\
d_m = \left|d\right|
\\
M_m = \left|M\right|

\\
\begin{array}{l}
t_0 := \frac{c0}{w \cdot h}\\
t_1 := \frac{d\_m}{D\_m} \cdot \sqrt{t\_0}\\
t_2 := \frac{c0}{2 \cdot w}\\
t_3 := \frac{c0 \cdot \left(d\_m \cdot d\_m\right)}{\left(D\_m \cdot D\_m\right) \cdot \left(w \cdot h\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(t\_1 + 0.5 \cdot \left(\frac{D\_m \cdot M\_m}{d\_m} \cdot \sqrt{\frac{w \cdot h}{c0}}\right), t\_1, t\_0 \cdot {\left(\frac{d\_m}{D\_m}\right)}^{2}\right)\\

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


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

    1. Initial program 69.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. Simplified70.8%

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

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

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

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \mathsf{fma}\left(\color{blue}{0.5 \cdot \left(\frac{D \cdot M}{d} \cdot \sqrt{\frac{h \cdot w}{c0}}\right) + \frac{d}{D} \cdot \sqrt{\frac{c0}{h \cdot w}}}, \frac{d}{D} \cdot \sqrt{\frac{c0}{h \cdot w}}, \frac{c0}{w \cdot h} \cdot {\left(\frac{d}{D}\right)}^{2}\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. Simplified21.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. Taylor expanded in c0 around -inf 3.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 53.6% accurate, 0.2× speedup?

\[\begin{array}{l} D_m = \left|D\right| \\ d_m = \left|d\right| \\ M_m = \left|M\right| \\ \begin{array}{l} t_0 := {\left(\frac{d\_m}{D\_m}\right)}^{2}\\ t_1 := \frac{c0}{w \cdot h}\\ t_2 := \frac{c0}{2 \cdot w}\\ t_3 := \frac{c0 \cdot \left(d\_m \cdot d\_m\right)}{\left(D\_m \cdot D\_m\right) \cdot \left(w \cdot h\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{M\_m + c0 \cdot \frac{t\_0}{w \cdot h}}, \frac{d\_m}{D\_m} \cdot \sqrt{t\_1}, t\_1 \cdot t\_0\right)\\ \mathbf{else}:\\ \;\;\;\;c0 \cdot \frac{0}{2 \cdot w}\\ \end{array} \end{array} \]
D_m = (fabs.f64 D)
d_m = (fabs.f64 d)
M_m = (fabs.f64 M)
(FPCore (c0 w h D_m d_m M_m)
 :precision binary64
 (let* ((t_0 (pow (/ d_m D_m) 2.0))
        (t_1 (/ c0 (* w h)))
        (t_2 (/ c0 (* 2.0 w)))
        (t_3 (/ (* c0 (* d_m d_m)) (* (* D_m D_m) (* w h)))))
   (if (<= (* t_2 (+ t_3 (sqrt (- (* t_3 t_3) (* M_m M_m))))) INFINITY)
     (*
      t_2
      (fma
       (sqrt (+ M_m (* c0 (/ t_0 (* w h)))))
       (* (/ d_m D_m) (sqrt t_1))
       (* t_1 t_0)))
     (* c0 (/ 0.0 (* 2.0 w))))))
D_m = fabs(D);
d_m = fabs(d);
M_m = fabs(M);
double code(double c0, double w, double h, double D_m, double d_m, double M_m) {
	double t_0 = pow((d_m / D_m), 2.0);
	double t_1 = c0 / (w * h);
	double t_2 = c0 / (2.0 * w);
	double t_3 = (c0 * (d_m * d_m)) / ((D_m * D_m) * (w * h));
	double tmp;
	if ((t_2 * (t_3 + sqrt(((t_3 * t_3) - (M_m * M_m))))) <= ((double) INFINITY)) {
		tmp = t_2 * fma(sqrt((M_m + (c0 * (t_0 / (w * h))))), ((d_m / D_m) * sqrt(t_1)), (t_1 * t_0));
	} else {
		tmp = c0 * (0.0 / (2.0 * w));
	}
	return tmp;
}
D_m = abs(D)
d_m = abs(d)
M_m = abs(M)
function code(c0, w, h, D_m, d_m, M_m)
	t_0 = Float64(d_m / D_m) ^ 2.0
	t_1 = Float64(c0 / Float64(w * h))
	t_2 = Float64(c0 / Float64(2.0 * w))
	t_3 = Float64(Float64(c0 * Float64(d_m * d_m)) / Float64(Float64(D_m * D_m) * Float64(w * h)))
	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(Float64(M_m + Float64(c0 * Float64(t_0 / Float64(w * h))))), Float64(Float64(d_m / D_m) * sqrt(t_1)), Float64(t_1 * t_0)));
	else
		tmp = Float64(c0 * Float64(0.0 / Float64(2.0 * w)));
	end
	return tmp
end
D_m = N[Abs[D], $MachinePrecision]
d_m = N[Abs[d], $MachinePrecision]
M_m = N[Abs[M], $MachinePrecision]
code[c0_, w_, h_, D$95$m_, d$95$m_, M$95$m_] := Block[{t$95$0 = N[Power[N[(d$95$m / D$95$m), $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$1 = N[(c0 / N[(w * h), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(c0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(N[(c0 * N[(d$95$m * d$95$m), $MachinePrecision]), $MachinePrecision] / N[(N[(D$95$m * D$95$m), $MachinePrecision] * N[(w * h), $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[(M$95$m + N[(c0 * N[(t$95$0 / N[(w * h), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(N[(d$95$m / D$95$m), $MachinePrecision] * N[Sqrt[t$95$1], $MachinePrecision]), $MachinePrecision] + N[(t$95$1 * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(c0 * N[(0.0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
D_m = \left|D\right|
\\
d_m = \left|d\right|
\\
M_m = \left|M\right|

\\
\begin{array}{l}
t_0 := {\left(\frac{d\_m}{D\_m}\right)}^{2}\\
t_1 := \frac{c0}{w \cdot h}\\
t_2 := \frac{c0}{2 \cdot w}\\
t_3 := \frac{c0 \cdot \left(d\_m \cdot d\_m\right)}{\left(D\_m \cdot D\_m\right) \cdot \left(w \cdot h\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{M\_m + c0 \cdot \frac{t\_0}{w \cdot h}}, \frac{d\_m}{D\_m} \cdot \sqrt{t\_1}, t\_1 \cdot t\_0\right)\\

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


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

    1. Initial program 69.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. Simplified70.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 54.4% accurate, 0.4× speedup?

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

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

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


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

    1. Initial program 69.0%

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

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

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

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

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

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

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

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

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

        \[\leadsto c0 \cdot \frac{2 \cdot \frac{\frac{c0}{\color{blue}{w \cdot h}} \cdot {d}^{2}}{{D}^{2}}}{2 \cdot w} \]
    8. Applied egg-rr74.2%

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

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

    1. Initial program 0.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 53.8% accurate, 0.4× speedup?

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

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

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


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

    1. Initial program 69.0%

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

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

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

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

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

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

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

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

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

    1. Initial program 0.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 54.4% accurate, 0.4× speedup?

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

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

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


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

    1. Initial program 69.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto c0 \cdot \frac{{d}^{2} \cdot \color{blue}{\frac{\frac{c0}{h \cdot w}}{{D}^{2}}}}{w} \]
      10. *-commutative74.2%

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

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

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

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

    1. Initial program 0.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 9: 54.0% accurate, 0.5× speedup?

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

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

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


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

    1. Initial program 69.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. Simplified70.8%

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

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

    1. Initial program 0.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 10: 34.1% accurate, 0.9× speedup?

\[\begin{array}{l} D_m = \left|D\right| \\ d_m = \left|d\right| \\ M_m = \left|M\right| \\ \begin{array}{l} t_0 := \frac{c0}{w \cdot h}\\ t_1 := t\_0 \cdot \frac{d\_m \cdot d\_m}{D\_m \cdot D\_m}\\ \mathbf{if}\;D\_m \leq 2 \cdot 10^{-81} \lor \neg \left(D\_m \leq 1.05 \cdot 10^{+112}\right):\\ \;\;\;\;c0 \cdot \frac{0}{2 \cdot w}\\ \mathbf{else}:\\ \;\;\;\;\frac{c0}{2 \cdot w} \cdot \left(\sqrt{t\_1 \cdot t\_1 - M\_m \cdot M\_m} + t\_0 \cdot \left(\frac{d\_m}{D\_m} \cdot \frac{d\_m}{D\_m}\right)\right)\\ \end{array} \end{array} \]
D_m = (fabs.f64 D)
d_m = (fabs.f64 d)
M_m = (fabs.f64 M)
(FPCore (c0 w h D_m d_m M_m)
 :precision binary64
 (let* ((t_0 (/ c0 (* w h))) (t_1 (* t_0 (/ (* d_m d_m) (* D_m D_m)))))
   (if (or (<= D_m 2e-81) (not (<= D_m 1.05e+112)))
     (* c0 (/ 0.0 (* 2.0 w)))
     (*
      (/ c0 (* 2.0 w))
      (+
       (sqrt (- (* t_1 t_1) (* M_m M_m)))
       (* t_0 (* (/ d_m D_m) (/ d_m D_m))))))))
D_m = fabs(D);
d_m = fabs(d);
M_m = fabs(M);
double code(double c0, double w, double h, double D_m, double d_m, double M_m) {
	double t_0 = c0 / (w * h);
	double t_1 = t_0 * ((d_m * d_m) / (D_m * D_m));
	double tmp;
	if ((D_m <= 2e-81) || !(D_m <= 1.05e+112)) {
		tmp = c0 * (0.0 / (2.0 * w));
	} else {
		tmp = (c0 / (2.0 * w)) * (sqrt(((t_1 * t_1) - (M_m * M_m))) + (t_0 * ((d_m / D_m) * (d_m / D_m))));
	}
	return tmp;
}
D_m = abs(d)
d_m = abs(d)
M_m = abs(m)
real(8) function code(c0, w, h, d_m, d_m_1, m_m)
    real(8), intent (in) :: c0
    real(8), intent (in) :: w
    real(8), intent (in) :: h
    real(8), intent (in) :: d_m
    real(8), intent (in) :: d_m_1
    real(8), intent (in) :: m_m
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = c0 / (w * h)
    t_1 = t_0 * ((d_m_1 * d_m_1) / (d_m * d_m))
    if ((d_m <= 2d-81) .or. (.not. (d_m <= 1.05d+112))) then
        tmp = c0 * (0.0d0 / (2.0d0 * w))
    else
        tmp = (c0 / (2.0d0 * w)) * (sqrt(((t_1 * t_1) - (m_m * m_m))) + (t_0 * ((d_m_1 / d_m) * (d_m_1 / d_m))))
    end if
    code = tmp
end function
D_m = Math.abs(D);
d_m = Math.abs(d);
M_m = Math.abs(M);
public static double code(double c0, double w, double h, double D_m, double d_m, double M_m) {
	double t_0 = c0 / (w * h);
	double t_1 = t_0 * ((d_m * d_m) / (D_m * D_m));
	double tmp;
	if ((D_m <= 2e-81) || !(D_m <= 1.05e+112)) {
		tmp = c0 * (0.0 / (2.0 * w));
	} else {
		tmp = (c0 / (2.0 * w)) * (Math.sqrt(((t_1 * t_1) - (M_m * M_m))) + (t_0 * ((d_m / D_m) * (d_m / D_m))));
	}
	return tmp;
}
D_m = math.fabs(D)
d_m = math.fabs(d)
M_m = math.fabs(M)
def code(c0, w, h, D_m, d_m, M_m):
	t_0 = c0 / (w * h)
	t_1 = t_0 * ((d_m * d_m) / (D_m * D_m))
	tmp = 0
	if (D_m <= 2e-81) or not (D_m <= 1.05e+112):
		tmp = c0 * (0.0 / (2.0 * w))
	else:
		tmp = (c0 / (2.0 * w)) * (math.sqrt(((t_1 * t_1) - (M_m * M_m))) + (t_0 * ((d_m / D_m) * (d_m / D_m))))
	return tmp
D_m = abs(D)
d_m = abs(d)
M_m = abs(M)
function code(c0, w, h, D_m, d_m, M_m)
	t_0 = Float64(c0 / Float64(w * h))
	t_1 = Float64(t_0 * Float64(Float64(d_m * d_m) / Float64(D_m * D_m)))
	tmp = 0.0
	if ((D_m <= 2e-81) || !(D_m <= 1.05e+112))
		tmp = Float64(c0 * Float64(0.0 / Float64(2.0 * w)));
	else
		tmp = Float64(Float64(c0 / Float64(2.0 * w)) * Float64(sqrt(Float64(Float64(t_1 * t_1) - Float64(M_m * M_m))) + Float64(t_0 * Float64(Float64(d_m / D_m) * Float64(d_m / D_m)))));
	end
	return tmp
end
D_m = abs(D);
d_m = abs(d);
M_m = abs(M);
function tmp_2 = code(c0, w, h, D_m, d_m, M_m)
	t_0 = c0 / (w * h);
	t_1 = t_0 * ((d_m * d_m) / (D_m * D_m));
	tmp = 0.0;
	if ((D_m <= 2e-81) || ~((D_m <= 1.05e+112)))
		tmp = c0 * (0.0 / (2.0 * w));
	else
		tmp = (c0 / (2.0 * w)) * (sqrt(((t_1 * t_1) - (M_m * M_m))) + (t_0 * ((d_m / D_m) * (d_m / D_m))));
	end
	tmp_2 = tmp;
end
D_m = N[Abs[D], $MachinePrecision]
d_m = N[Abs[d], $MachinePrecision]
M_m = N[Abs[M], $MachinePrecision]
code[c0_, w_, h_, D$95$m_, d$95$m_, 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$95$m * d$95$m), $MachinePrecision] / N[(D$95$m * D$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[D$95$m, 2e-81], N[Not[LessEqual[D$95$m, 1.05e+112]], $MachinePrecision]], N[(c0 * N[(0.0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision] * N[(N[Sqrt[N[(N[(t$95$1 * t$95$1), $MachinePrecision] - N[(M$95$m * M$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + N[(t$95$0 * N[(N[(d$95$m / D$95$m), $MachinePrecision] * N[(d$95$m / D$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
D_m = \left|D\right|
\\
d_m = \left|d\right|
\\
M_m = \left|M\right|

\\
\begin{array}{l}
t_0 := \frac{c0}{w \cdot h}\\
t_1 := t\_0 \cdot \frac{d\_m \cdot d\_m}{D\_m \cdot D\_m}\\
\mathbf{if}\;D\_m \leq 2 \cdot 10^{-81} \lor \neg \left(D\_m \leq 1.05 \cdot 10^{+112}\right):\\
\;\;\;\;c0 \cdot \frac{0}{2 \cdot w}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if D < 1.9999999999999999e-81 or 1.0499999999999999e112 < D

    1. Initial program 23.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto c0 \cdot \frac{\color{blue}{0}}{2 \cdot w} \]

    if 1.9999999999999999e-81 < D < 1.0499999999999999e112

    1. Initial program 28.8%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;D \leq 2 \cdot 10^{-81} \lor \neg \left(D \leq 1.05 \cdot 10^{+112}\right):\\ \;\;\;\;c0 \cdot \frac{0}{2 \cdot w}\\ \mathbf{else}:\\ \;\;\;\;\frac{c0}{2 \cdot w} \cdot \left(\sqrt{\left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\right) \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\right) - M \cdot M} + \frac{c0}{w \cdot h} \cdot \left(\frac{d}{D} \cdot \frac{d}{D}\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 33.7% accurate, 21.6× speedup?

\[\begin{array}{l} D_m = \left|D\right| \\ d_m = \left|d\right| \\ M_m = \left|M\right| \\ c0 \cdot \frac{0}{2 \cdot w} \end{array} \]
D_m = (fabs.f64 D)
d_m = (fabs.f64 d)
M_m = (fabs.f64 M)
(FPCore (c0 w h D_m d_m M_m) :precision binary64 (* c0 (/ 0.0 (* 2.0 w))))
D_m = fabs(D);
d_m = fabs(d);
M_m = fabs(M);
double code(double c0, double w, double h, double D_m, double d_m, double M_m) {
	return c0 * (0.0 / (2.0 * w));
}
D_m = abs(d)
d_m = abs(d)
M_m = abs(m)
real(8) function code(c0, w, h, d_m, d_m_1, m_m)
    real(8), intent (in) :: c0
    real(8), intent (in) :: w
    real(8), intent (in) :: h
    real(8), intent (in) :: d_m
    real(8), intent (in) :: d_m_1
    real(8), intent (in) :: m_m
    code = c0 * (0.0d0 / (2.0d0 * w))
end function
D_m = Math.abs(D);
d_m = Math.abs(d);
M_m = Math.abs(M);
public static double code(double c0, double w, double h, double D_m, double d_m, double M_m) {
	return c0 * (0.0 / (2.0 * w));
}
D_m = math.fabs(D)
d_m = math.fabs(d)
M_m = math.fabs(M)
def code(c0, w, h, D_m, d_m, M_m):
	return c0 * (0.0 / (2.0 * w))
D_m = abs(D)
d_m = abs(d)
M_m = abs(M)
function code(c0, w, h, D_m, d_m, M_m)
	return Float64(c0 * Float64(0.0 / Float64(2.0 * w)))
end
D_m = abs(D);
d_m = abs(d);
M_m = abs(M);
function tmp = code(c0, w, h, D_m, d_m, M_m)
	tmp = c0 * (0.0 / (2.0 * w));
end
D_m = N[Abs[D], $MachinePrecision]
d_m = N[Abs[d], $MachinePrecision]
M_m = N[Abs[M], $MachinePrecision]
code[c0_, w_, h_, D$95$m_, d$95$m_, M$95$m_] := N[(c0 * N[(0.0 / N[(2.0 * w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
D_m = \left|D\right|
\\
d_m = \left|d\right|
\\
M_m = \left|M\right|

\\
c0 \cdot \frac{0}{2 \cdot w}
\end{array}
Derivation
  1. Initial program 24.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto c0 \cdot \frac{\color{blue}{0}}{2 \cdot w} \]
  7. Add Preprocessing

Reproduce

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