Average Error: 0.0 → 0.0
Time: 2.6s
Precision: binary64
Cost: 6720
\[\left(x + y\right) - x \cdot y \]
\[\mathsf{fma}\left(y, 1 - x, x\right) \]
(FPCore (x y) :precision binary64 (- (+ x y) (* x y)))
(FPCore (x y) :precision binary64 (fma y (- 1.0 x) x))
double code(double x, double y) {
	return (x + y) - (x * y);
}
double code(double x, double y) {
	return fma(y, (1.0 - x), x);
}
function code(x, y)
	return Float64(Float64(x + y) - Float64(x * y))
end
function code(x, y)
	return fma(y, Float64(1.0 - x), x)
end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision]
code[x_, y_] := N[(y * N[(1.0 - x), $MachinePrecision] + x), $MachinePrecision]
\left(x + y\right) - x \cdot y
\mathsf{fma}\left(y, 1 - x, x\right)

Error

Derivation

  1. Initial program 0.0

    \[\left(x + y\right) - x \cdot y \]
  2. Simplified0.0

    \[\leadsto \color{blue}{\mathsf{fma}\left(y, 1 - x, x\right)} \]
    Proof
    (fma.f64 y (-.f64 1 x) x): 0 points increase in error, 0 points decrease in error
    (fma.f64 y (Rewrite<= unsub-neg_binary64 (+.f64 1 (neg.f64 x))) x): 0 points increase in error, 0 points decrease in error
    (fma.f64 y (Rewrite<= +-commutative_binary64 (+.f64 (neg.f64 x) 1)) x): 0 points increase in error, 0 points decrease in error
    (Rewrite<= fma-def_binary64 (+.f64 (*.f64 y (+.f64 (neg.f64 x) 1)) x)): 0 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 (+.f64 (neg.f64 x) 1) y)) x): 0 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite<= distribute-rgt1-in_binary64 (+.f64 y (*.f64 (neg.f64 x) y))) x): 0 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite<= cancel-sign-sub-inv_binary64 (-.f64 y (*.f64 x y))) x): 0 points increase in error, 0 points decrease in error
    (Rewrite<= +-commutative_binary64 (+.f64 x (-.f64 y (*.f64 x y)))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= associate--l+_binary64 (-.f64 (+.f64 x y) (*.f64 x y))): 0 points increase in error, 0 points decrease in error
  3. Final simplification0.0

    \[\leadsto \mathsf{fma}\left(y, 1 - x, x\right) \]

Alternatives

Alternative 1
Error25.5
Cost1048
\[\begin{array}{l} t_0 := y \cdot \left(-x\right)\\ \mathbf{if}\;x \leq -3.2 \cdot 10^{+61}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1.85 \cdot 10^{+45}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -6.8 \cdot 10^{-90}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -8.6 \cdot 10^{-207}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \leq -3.1 \cdot 10^{-236}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error20.4
Cost717
\[\begin{array}{l} \mathbf{if}\;x \leq -5.8 \cdot 10^{-90}:\\ \;\;\;\;x \cdot \left(1 - y\right)\\ \mathbf{elif}\;x \leq -8.6 \cdot 10^{-207} \lor \neg \left(x \leq -3.1 \cdot 10^{-236}\right):\\ \;\;\;\;y \cdot \left(1 - x\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Error19.3
Cost584
\[\begin{array}{l} \mathbf{if}\;y \leq -1:\\ \;\;\;\;y \cdot \left(-x\right)\\ \mathbf{elif}\;y \leq 2.9 \cdot 10^{-59}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(1 - x\right)\\ \end{array} \]
Alternative 4
Error0.0
Cost448
\[\left(y + x\right) - y \cdot x \]
Alternative 5
Error27.8
Cost196
\[\begin{array}{l} \mathbf{if}\;y \leq 2.9 \cdot 10^{-59}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]
Alternative 6
Error36.3
Cost64
\[x \]

Error

Reproduce

herbie shell --seed 2022343 
(FPCore (x y)
  :name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, A"
  :precision binary64
  (- (+ x y) (* x y)))