Average Error: 10.2 → 0.3
Time: 8.9s
Precision: binary64
Cost: 7040
$\left(\left(\left(\left(0 \leq n \land n \leq 1000\right) \land \left(-1000 \leq sumxy \land sumxy \leq 1000\right)\right) \land \left(-1000 \leq sumx \land sumx \leq 1000\right)\right) \land \left(-1000 \leq sumy \land sumy \leq 1000\right)\right) \land \left(-1000 \leq denom \land denom \leq 1000\right)$
$\begin{array}{c}[n, sumxy] = \mathsf{sort}([n, sumxy])\\ [sumx, sumy] = \mathsf{sort}([sumx, sumy])\\ \end{array}$
$\frac{n \cdot sumxy - sumx \cdot sumy}{denom}$
$\mathsf{fma}\left(n, \frac{sumxy}{denom}, \frac{sumx}{denom} \cdot \left(-sumy\right)\right)$
(FPCore (n sumxy sumx sumy denom)
:precision binary64
(/ (- (* n sumxy) (* sumx sumy)) denom))
(FPCore (n sumxy sumx sumy denom)
:precision binary64
(fma n (/ sumxy denom) (* (/ sumx denom) (- sumy))))
double code(double n, double sumxy, double sumx, double sumy, double denom) {
return ((n * sumxy) - (sumx * sumy)) / denom;
}

double code(double n, double sumxy, double sumx, double sumy, double denom) {
return fma(n, (sumxy / denom), ((sumx / denom) * -sumy));
}

function code(n, sumxy, sumx, sumy, denom)
return Float64(Float64(Float64(n * sumxy) - Float64(sumx * sumy)) / denom)
end

function code(n, sumxy, sumx, sumy, denom)
return fma(n, Float64(sumxy / denom), Float64(Float64(sumx / denom) * Float64(-sumy)))
end

code[n_, sumxy_, sumx_, sumy_, denom_] := N[(N[(N[(n * sumxy), $MachinePrecision] - N[(sumx * sumy),$MachinePrecision]), $MachinePrecision] / denom),$MachinePrecision]

code[n_, sumxy_, sumx_, sumy_, denom_] := N[(n * N[(sumxy / denom), $MachinePrecision] + N[(N[(sumx / denom),$MachinePrecision] * (-sumy)), $MachinePrecision]),$MachinePrecision]

\frac{n \cdot sumxy - sumx \cdot sumy}{denom}

\mathsf{fma}\left(n, \frac{sumxy}{denom}, \frac{sumx}{denom} \cdot \left(-sumy\right)\right)


# Derivation

1. Initial program 10.2

$\frac{n \cdot sumxy - sumx \cdot sumy}{denom}$
2. Applied egg-rr0.3

$\leadsto \color{blue}{\mathsf{fma}\left(\frac{n}{1}, \frac{sumxy}{denom}, -\frac{sumx}{\frac{denom}{sumy}}\right)}$
3. Applied egg-rr0.3

$\leadsto \mathsf{fma}\left(\frac{n}{1}, \frac{sumxy}{denom}, -\color{blue}{sumy \cdot \frac{sumx}{denom}}\right)$
4. Final simplification0.3

$\leadsto \mathsf{fma}\left(n, \frac{sumxy}{denom}, \frac{sumx}{denom} \cdot \left(-sumy\right)\right)$

# Alternatives

Alternative 1
Error5.5
Cost1096
$\begin{array}{l} t_0 := \frac{n \cdot sumxy - sumy \cdot sumx}{denom}\\ \mathbf{if}\;n \cdot sumxy \leq -2 \cdot 10^{-320}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;n \cdot sumxy \leq 0:\\ \;\;\;\;\frac{sumx}{denom} \cdot \left(-sumy\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array}$
Alternative 2
Error19.4
Cost912
$\begin{array}{l} t_0 := sumx \cdot \frac{-sumy}{denom}\\ \mathbf{if}\;sumx \leq -3.60440928091478 \cdot 10^{-91}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;sumx \leq -1.6565276756463553 \cdot 10^{-135}:\\ \;\;\;\;sumxy \cdot \frac{n}{denom}\\ \mathbf{elif}\;sumx \leq -1.5994425465466402 \cdot 10^{-155}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;sumx \leq 1.0011034748185995 \cdot 10^{-235}:\\ \;\;\;\;n \cdot \frac{sumxy}{denom}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array}$
Alternative 3
Error19.4
Cost912
$\begin{array}{l} t_0 := \frac{sumx}{denom} \cdot \left(-sumy\right)\\ \mathbf{if}\;sumx \leq -3.60440928091478 \cdot 10^{-91}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;sumx \leq -1.6565276756463553 \cdot 10^{-135}:\\ \;\;\;\;sumxy \cdot \frac{n}{denom}\\ \mathbf{elif}\;sumx \leq -1.5994425465466402 \cdot 10^{-155}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;sumx \leq 1.0011034748185995 \cdot 10^{-235}:\\ \;\;\;\;n \cdot \frac{sumxy}{denom}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array}$
Alternative 4
Error0.3
Cost704
$\frac{n}{\frac{denom}{sumxy}} - \frac{sumx}{\frac{denom}{sumy}}$
Alternative 5
Error30.3
Cost320
$sumxy \cdot \frac{n}{denom}$
Alternative 6
Error30.3
Cost320
$n \cdot \frac{sumxy}{denom}$

# Reproduce

herbie shell --seed 1
(FPCore (n sumxy sumx sumy denom)
:name "((n * sumxy) - (sumx * sumy )) / denom"
:precision binary64
:pre (and (and (and (and (and (<= 0.0 n) (<= n 1000.0)) (and (<= -1000.0 sumxy) (<= sumxy 1000.0))) (and (<= -1000.0 sumx) (<= sumx 1000.0))) (and (<= -1000.0 sumy) (<= sumy 1000.0))) (and (<= -1000.0 denom) (<= denom 1000.0)))
(/ (- (* n sumxy) (* sumx sumy)) denom))