?

Average Accuracy: 100.0% → 100.0%
Time: 3.2s
Precision: binary64
Cost: 6720

?

\[ \begin{array}{c}[x, y] = \mathsf{sort}([x, y])\\ \end{array} \]
\[\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 100.0%

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

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

    [Start]100.0

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

    associate--l+ [=>]100.0

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

    +-commutative [=>]100.0

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

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

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

    distribute-rgt1-in [=>]100.0

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

    *-commutative [=>]100.0

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

    fma-def [=>]100.0

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

    +-commutative [=>]100.0

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

    unsub-neg [=>]100.0

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

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

Alternatives

Alternative 1
Accuracy85.6%
Cost848
\[\begin{array}{l} \mathbf{if}\;y \leq -1:\\ \;\;\;\;y \cdot \left(-x\right)\\ \mathbf{elif}\;y \leq 6.2 \cdot 10^{-197}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 6.1 \cdot 10^{-149}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 2.3 \cdot 10^{-74}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(1 - x\right)\\ \end{array} \]
Alternative 2
Accuracy86.2%
Cost716
\[\begin{array}{l} \mathbf{if}\;y \leq 6.2 \cdot 10^{-197}:\\ \;\;\;\;x \cdot \left(1 - y\right)\\ \mathbf{elif}\;y \leq 6.1 \cdot 10^{-149}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 4.7 \cdot 10^{-75}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(1 - x\right)\\ \end{array} \]
Alternative 3
Accuracy86.2%
Cost716
\[\begin{array}{l} \mathbf{if}\;y \leq 6.2 \cdot 10^{-197}:\\ \;\;\;\;x - y \cdot x\\ \mathbf{elif}\;y \leq 6.1 \cdot 10^{-149}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 1.85 \cdot 10^{-74}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(1 - x\right)\\ \end{array} \]
Alternative 4
Accuracy75.0%
Cost592
\[\begin{array}{l} \mathbf{if}\;y \leq -1:\\ \;\;\;\;y \cdot \left(-x\right)\\ \mathbf{elif}\;y \leq 6.2 \cdot 10^{-197}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 6.1 \cdot 10^{-149}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 2.2 \cdot 10^{-74}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]
Alternative 5
Accuracy71.8%
Cost460
\[\begin{array}{l} \mathbf{if}\;y \leq 6.2 \cdot 10^{-197}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 2.9 \cdot 10^{-148}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 2.35 \cdot 10^{-74}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]
Alternative 6
Accuracy100.0%
Cost448
\[\left(y + x\right) - y \cdot x \]
Alternative 7
Accuracy42.9%
Cost64
\[x \]

Error

Reproduce?

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