Average Error: 21.5 → 5.4
Time: 15.8s
Precision: binary64
Cost: 14276
$\left(\left(\left(\left(0 \leq N \land N \leq 1000\right) \land \left(0 \leq sxy \land sxy \leq 1000\right)\right) \land \left(0 \leq sx \land sx \leq 1000\right)\right) \land \left(0 \leq sy \land sy \leq 1000\right)\right) \land \left(0 \leq sxx \land sxx \leq 1000\right)$
$\frac{N \cdot sxy - sx \cdot sy}{N \cdot sxx - sx \cdot sx}$
$\begin{array}{l} t_0 := \mathsf{fma}\left(sx, -sx, N \cdot sxx\right)\\ \mathbf{if}\;sx \leq 4.223635969993328 \cdot 10^{-159}:\\ \;\;\;\;\frac{sxy - sx \cdot \frac{sy}{N}}{sxx}\\ \mathbf{else}:\\ \;\;\;\;\frac{N}{\frac{t_0}{sxy}} - \frac{sx}{\frac{t_0}{sy}}\\ \end{array}$
(FPCore (N sxy sx sy sxx)
:precision binary64
(/ (- (* N sxy) (* sx sy)) (- (* N sxx) (* sx sx))))
(FPCore (N sxy sx sy sxx)
:precision binary64
(let* ((t_0 (fma sx (- sx) (* N sxx))))
(if (<= sx 4.223635969993328e-159)
(/ (- sxy (* sx (/ sy N))) sxx)
(- (/ N (/ t_0 sxy)) (/ sx (/ t_0 sy))))))
double code(double N, double sxy, double sx, double sy, double sxx) {
return ((N * sxy) - (sx * sy)) / ((N * sxx) - (sx * sx));
}

double code(double N, double sxy, double sx, double sy, double sxx) {
double t_0 = fma(sx, -sx, (N * sxx));
double tmp;
if (sx <= 4.223635969993328e-159) {
tmp = (sxy - (sx * (sy / N))) / sxx;
} else {
tmp = (N / (t_0 / sxy)) - (sx / (t_0 / sy));
}
return tmp;
}

function code(N, sxy, sx, sy, sxx)
return Float64(Float64(Float64(N * sxy) - Float64(sx * sy)) / Float64(Float64(N * sxx) - Float64(sx * sx)))
end

function code(N, sxy, sx, sy, sxx)
t_0 = fma(sx, Float64(-sx), Float64(N * sxx))
tmp = 0.0
if (sx <= 4.223635969993328e-159)
tmp = Float64(Float64(sxy - Float64(sx * Float64(sy / N))) / sxx);
else
tmp = Float64(Float64(N / Float64(t_0 / sxy)) - Float64(sx / Float64(t_0 / sy)));
end
return tmp
end

code[N_, sxy_, sx_, sy_, sxx_] := N[(N[(N[(N * sxy), $MachinePrecision] - N[(sx * sy),$MachinePrecision]), $MachinePrecision] / N[(N[(N * sxx),$MachinePrecision] - N[(sx * sx), $MachinePrecision]),$MachinePrecision]), $MachinePrecision]  code[N_, sxy_, sx_, sy_, sxx_] := Block[{t$95$0 = N[(sx * (-sx) + N[(N * sxx),$MachinePrecision]), $MachinePrecision]}, If[LessEqual[sx, 4.223635969993328e-159], N[(N[(sxy - N[(sx * N[(sy / N),$MachinePrecision]), $MachinePrecision]),$MachinePrecision] / sxx), $MachinePrecision], N[(N[(N / N[(t$95$0 / sxy),$MachinePrecision]), $MachinePrecision] - N[(sx / N[(t$95$0 / sy),$MachinePrecision]), $MachinePrecision]),$MachinePrecision]]]

\frac{N \cdot sxy - sx \cdot sy}{N \cdot sxx - sx \cdot sx}

\begin{array}{l}
t_0 := \mathsf{fma}\left(sx, -sx, N \cdot sxx\right)\\
\mathbf{if}\;sx \leq 4.223635969993328 \cdot 10^{-159}:\\
\;\;\;\;\frac{sxy - sx \cdot \frac{sy}{N}}{sxx}\\

\mathbf{else}:\\
\;\;\;\;\frac{N}{\frac{t_0}{sxy}} - \frac{sx}{\frac{t_0}{sy}}\\

\end{array}


# Derivation

1. Split input into 2 regimes
2. ## if sx < 4.22363596999332806e-159

1. Initial program 36.8

$\frac{N \cdot sxy - sx \cdot sy}{N \cdot sxx - sx \cdot sx}$
2. Taylor expanded in N around inf 37.0

$\leadsto \frac{N \cdot sxy - sx \cdot sy}{\color{blue}{sxx \cdot N}}$
3. Taylor expanded in N around 0 31.6

$\leadsto \color{blue}{\frac{sxy}{sxx} + -1 \cdot \frac{sx \cdot sy}{sxx \cdot N}}$
4. Simplified10.5

$\leadsto \color{blue}{\frac{sxy - sx \cdot \frac{sy}{N}}{sxx}}$

## if 4.22363596999332806e-159 < sx

1. Initial program 7.2

$\frac{N \cdot sxy - sx \cdot sy}{N \cdot sxx - sx \cdot sx}$
2. Applied egg-rr0.5

$\leadsto \color{blue}{\frac{N}{\frac{\mathsf{fma}\left(sx, -sx, N \cdot sxx\right)}{sxy}} - \frac{sx}{\frac{\mathsf{fma}\left(sx, -sx, N \cdot sxx\right)}{sy}}}$
3. Recombined 2 regimes into one program.
4. Final simplification5.4

$\leadsto \begin{array}{l} \mathbf{if}\;sx \leq 4.223635969993328 \cdot 10^{-159}:\\ \;\;\;\;\frac{sxy - sx \cdot \frac{sy}{N}}{sxx}\\ \mathbf{else}:\\ \;\;\;\;\frac{N}{\frac{\mathsf{fma}\left(sx, -sx, N \cdot sxx\right)}{sxy}} - \frac{sx}{\frac{\mathsf{fma}\left(sx, -sx, N \cdot sxx\right)}{sy}}\\ \end{array}$

# Alternatives

Alternative 1
Error9.0
Cost7748
$\begin{array}{l} \mathbf{if}\;sx \leq 1.3588282028797376 \cdot 10^{-158}:\\ \;\;\;\;\frac{sxy - sx \cdot \frac{sy}{N}}{sxx}\\ \mathbf{else}:\\ \;\;\;\;\frac{N}{\frac{\mathsf{fma}\left(sx, -sx, N \cdot sxx\right)}{sxy}} - \frac{sx}{\frac{-sx \cdot sx}{sy}}\\ \end{array}$
Alternative 2
Error8.8
Cost7428
$\begin{array}{l} \mathbf{if}\;sx \leq 3.5982393265981974 \cdot 10^{-160}:\\ \;\;\;\;\frac{sxy - sx \cdot \frac{sy}{N}}{sxx}\\ \mathbf{else}:\\ \;\;\;\;\frac{sx \cdot sy - sxy \cdot N}{\mathsf{fma}\left(sx, sx, N \cdot \left(-sxx\right)\right)}\\ \end{array}$
Alternative 3
Error8.8
Cost1092
$\begin{array}{l} \mathbf{if}\;sx \leq 3.5982393265981974 \cdot 10^{-160}:\\ \;\;\;\;\frac{sxy - sx \cdot \frac{sy}{N}}{sxx}\\ \mathbf{else}:\\ \;\;\;\;\frac{sxy \cdot N - sx \cdot sy}{N \cdot sxx - sx \cdot sx}\\ \end{array}$
Alternative 4
Error14.2
Cost836
$\begin{array}{l} \mathbf{if}\;sx \leq 1.3588282028797376 \cdot 10^{-158}:\\ \;\;\;\;\frac{sxy - sx \cdot \frac{sy}{N}}{sxx}\\ \mathbf{else}:\\ \;\;\;\;\frac{sx \cdot sy - sxy \cdot N}{sx \cdot sx}\\ \end{array}$
Alternative 5
Error11.1
Cost836
$\begin{array}{l} \mathbf{if}\;sx \leq 1.3588282028797376 \cdot 10^{-158}:\\ \;\;\;\;\frac{sxy - sx \cdot \frac{sy}{N}}{sxx}\\ \mathbf{else}:\\ \;\;\;\;\frac{sy}{sx} - \frac{N}{sx \cdot \frac{sx}{sxy}}\\ \end{array}$
Alternative 6
Error27.8
Cost776
$\begin{array}{l} \mathbf{if}\;sx \leq 5.424873084314608 \cdot 10^{-246}:\\ \;\;\;\;\frac{sxy}{sxx}\\ \mathbf{elif}\;sx \leq 2.6728071362714618 \cdot 10^{-210}:\\ \;\;\;\;sy \cdot \left(-\frac{\frac{sx}{N}}{sxx}\right)\\ \mathbf{elif}\;sx \leq 1.3588282028797376 \cdot 10^{-158}:\\ \;\;\;\;\frac{sxy}{sxx}\\ \mathbf{else}:\\ \;\;\;\;\frac{sy}{sx}\\ \end{array}$
Alternative 7
Error27.8
Cost776
$\begin{array}{l} \mathbf{if}\;sx \leq 5.424873084314608 \cdot 10^{-246}:\\ \;\;\;\;\frac{sxy}{sxx}\\ \mathbf{elif}\;sx \leq 2.6728071362714618 \cdot 10^{-210}:\\ \;\;\;\;\frac{sy}{N} \cdot \frac{-sx}{sxx}\\ \mathbf{elif}\;sx \leq 1.3588282028797376 \cdot 10^{-158}:\\ \;\;\;\;\frac{sxy}{sxx}\\ \mathbf{else}:\\ \;\;\;\;\frac{sy}{sx}\\ \end{array}$
Alternative 8
Error18.5
Cost708
$\begin{array}{l} \mathbf{if}\;sx \leq 1.3588282028797376 \cdot 10^{-158}:\\ \;\;\;\;\frac{sxy - sx \cdot \frac{sy}{N}}{sxx}\\ \mathbf{else}:\\ \;\;\;\;\frac{sy}{sx}\\ \end{array}$
Alternative 9
Error25.0
Cost324
$\begin{array}{l} \mathbf{if}\;sx \leq 1.3588282028797376 \cdot 10^{-158}:\\ \;\;\;\;\frac{sxy}{sxx}\\ \mathbf{else}:\\ \;\;\;\;\frac{sy}{sx}\\ \end{array}$
Alternative 10
Error40.1
Cost192
$\frac{sxy}{sxx}$

# Reproduce

herbie shell --seed 1
(FPCore (N sxy sx sy sxx)
:name "(N * sxy - sx * sy) / (N * sxx - sx * sx)"
:precision binary64
:pre (and (and (and (and (and (<= 0.0 N) (<= N 1000.0)) (and (<= 0.0 sxy) (<= sxy 1000.0))) (and (<= 0.0 sx) (<= sx 1000.0))) (and (<= 0.0 sy) (<= sy 1000.0))) (and (<= 0.0 sxx) (<= sxx 1000.0)))
(/ (- (* N sxy) (* sx sy)) (- (* N sxx) (* sx sx))))