Henrywood and Agarwal, Equation (13)

Percentage Accurate: 24.3% → 55.3%
Time: 27.3s
Alternatives: 6
Speedup: 151.0×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

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

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

\\
\begin{array}{l}
t_0 := \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(w \cdot h\right) \cdot \left(D\_m \cdot D\_m\right)}\\
t_3 := t\_1 \cdot \left(t\_2 + \sqrt{t\_2 \cdot t\_2 - M \cdot M}\right)\\
\mathbf{if}\;t\_3 \leq 5 \cdot 10^{+256}:\\
\;\;\;\;t\_3\\

\mathbf{elif}\;t\_3 \leq \infty:\\
\;\;\;\;t\_1 \cdot \left(t\_0 \cdot \left(\frac{d\_m}{D\_m} \cdot \frac{d\_m}{D\_m}\right) + \sqrt{\mathsf{fma}\left({\left(\frac{d\_m}{D\_m}\right)}^{2}, t\_0, M\right)} \cdot \left(\frac{d\_m}{D\_m} \cdot \sqrt{t\_0}\right)\right)\\

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


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

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

    if 5.00000000000000015e256 < (*.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 74.4%

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

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

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

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(\frac{c0}{w \cdot h} \cdot \color{blue}{\left(\frac{d}{D} \cdot \frac{d}{D}\right)} + \sqrt{\left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\right) \cdot \left(\frac{c0}{w \cdot h} \cdot \frac{d \cdot d}{D \cdot D}\right) - M \cdot M}\right) \]
    6. Step-by-step derivation
      1. pow1/274.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\log \color{blue}{1}}{w} \cdot -0.5 \]
    10. Taylor expanded in w around 0 44.4%

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

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

Alternative 2: 54.6% accurate, 0.5× speedup?

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

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

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


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

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

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

    1. Initial program 0.0%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\log \color{blue}{1}}{w} \cdot -0.5 \]
    10. Taylor expanded in w around 0 44.4%

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

Alternative 3: 32.9% accurate, 1.0× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if h < -2.0500000000000002e38

    1. Initial program 37.9%

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

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

    if -2.0500000000000002e38 < h

    1. Initial program 22.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. Simplified32.6%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\log \color{blue}{1}}{w} \cdot -0.5 \]
    10. Taylor expanded in w around 0 36.8%

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

Alternative 4: 32.8% accurate, 1.0× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if h < -1.75e40

    1. Initial program 37.9%

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

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

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

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

      \[\leadsto \frac{c0}{2 \cdot w} \cdot \left(\frac{c0}{w \cdot h} \cdot \left(\frac{d}{D} \cdot \frac{d}{D}\right) + \sqrt{\left(\color{blue}{\frac{c0}{h \cdot w}} \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) \]
    7. Step-by-step derivation
      1. *-commutative37.9%

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

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

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

    if -1.75e40 < h

    1. Initial program 22.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. Simplified32.6%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\log \color{blue}{1}}{w} \cdot -0.5 \]
    10. Taylor expanded in w around 0 36.8%

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

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

Alternative 5: 32.8% accurate, 1.0× speedup?

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if h < -2.29999999999999996e36

    1. Initial program 37.9%

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

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

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

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

    if -2.29999999999999996e36 < h

    1. Initial program 22.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. Simplified32.6%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\log \color{blue}{1}}{w} \cdot -0.5 \]
    10. Taylor expanded in w around 0 36.8%

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

Alternative 6: 33.9% accurate, 151.0× speedup?

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

\\
0
\end{array}
Derivation
  1. Initial program 24.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. Simplified35.3%

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \frac{\log \color{blue}{1}}{w} \cdot -0.5 \]
  10. Taylor expanded in w around 0 34.0%

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

Reproduce

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