?

Average Error: 0.01% → 0.01%
Time: 2.8s
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.01

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

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

    [Start]0.01

    \[ \left(x + y\right) - x \cdot y \]

    associate--l+ [=>]0.01

    \[ \color{blue}{x + \left(y - x \cdot y\right)} \]

    +-commutative [=>]0.01

    \[ \color{blue}{\left(y - x \cdot y\right) + x} \]

    cancel-sign-sub-inv [=>]0.01

    \[ \color{blue}{\left(y + \left(-x\right) \cdot y\right)} + x \]

    distribute-rgt1-in [=>]0.01

    \[ \color{blue}{\left(\left(-x\right) + 1\right) \cdot y} + x \]

    *-commutative [=>]0.01

    \[ \color{blue}{y \cdot \left(\left(-x\right) + 1\right)} + x \]

    fma-def [=>]0.01

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

    +-commutative [=>]0.01

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

    unsub-neg [=>]0.01

    \[ \mathsf{fma}\left(y, \color{blue}{1 - x}, x\right) \]
  3. Final simplification0.01

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

Alternatives

Alternative 1
Error37.75%
Cost1048
\[\begin{array}{l} t_0 := y \cdot \left(-x\right)\\ \mathbf{if}\;x \leq -7.1 \cdot 10^{+168}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -7.2 \cdot 10^{+128}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -2 \cdot 10^{-28}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -9.2 \cdot 10^{-73}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \leq -2.8 \cdot 10^{-111}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error15.95%
Cost850
\[\begin{array}{l} \mathbf{if}\;x \leq -2 \cdot 10^{-28} \lor \neg \left(x \leq -3.2 \cdot 10^{-74} \lor \neg \left(x \leq -2 \cdot 10^{-111}\right) \land x \leq 8 \cdot 10^{-5}\right):\\ \;\;\;\;x \cdot \left(1 - y\right)\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]
Alternative 3
Error28.98%
Cost716
\[\begin{array}{l} t_0 := x \cdot \left(1 - y\right)\\ \mathbf{if}\;x \leq -1.7 \cdot 10^{-28}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -6.5 \cdot 10^{-74}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \leq -2.8 \cdot 10^{-111}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;y - y \cdot x\\ \end{array} \]
Alternative 4
Error43.7%
Cost460
\[\begin{array}{l} \mathbf{if}\;x \leq -3.6 \cdot 10^{-28}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1.36 \cdot 10^{-70}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \leq -2.7 \cdot 10^{-111}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]
Alternative 5
Error0.01%
Cost448
\[\left(y + x\right) - y \cdot x \]
Alternative 6
Error57.15%
Cost64
\[x \]

Error

Reproduce?

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