?

Average Error: 0.02% → 0%
Time: 3.0s
Precision: binary64
Cost: 6720

?

\[\left(x + 1\right) \cdot y - x \]
\[\mathsf{fma}\left(x, y, y - x\right) \]
(FPCore (x y) :precision binary64 (- (* (+ x 1.0) y) x))
(FPCore (x y) :precision binary64 (fma x y (- y x)))
double code(double x, double y) {
	return ((x + 1.0) * y) - x;
}
double code(double x, double y) {
	return fma(x, y, (y - x));
}
function code(x, y)
	return Float64(Float64(Float64(x + 1.0) * y) - x)
end
function code(x, y)
	return fma(x, y, Float64(y - x))
end
code[x_, y_] := N[(N[(N[(x + 1.0), $MachinePrecision] * y), $MachinePrecision] - x), $MachinePrecision]
code[x_, y_] := N[(x * y + N[(y - x), $MachinePrecision]), $MachinePrecision]
\left(x + 1\right) \cdot y - x
\mathsf{fma}\left(x, y, y - x\right)

Error?

Derivation?

  1. Initial program 0.02

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

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

    [Start]0.02

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

    sub-neg [=>]0.02

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

    *-commutative [=>]0.02

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

    distribute-lft-in [=>]0.01

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

    associate-+l+ [=>]0.01

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

    *-commutative [=>]0.01

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

    *-lft-identity [<=]0.01

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

    *-commutative [<=]0.01

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

    fma-def [=>]0

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

    *-commutative [=>]0

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

    *-lft-identity [=>]0

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

    sub-neg [<=]0

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

    *-commutative [=>]0

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

    *-lft-identity [=>]0

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

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

Alternatives

Alternative 1
Error15.53%
Cost848
\[\begin{array}{l} t_0 := y \cdot \left(x + 1\right)\\ t_1 := x \cdot \left(y + -1\right)\\ \mathbf{if}\;y \leq -2 \cdot 10^{-12}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 6.2 \cdot 10^{-75}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 4.4 \cdot 10^{-11}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 1.3:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error15.5%
Cost848
\[\begin{array}{l} t_0 := y \cdot \left(x + 1\right)\\ \mathbf{if}\;y \leq -8.8 \cdot 10^{-13}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 5.6 \cdot 10^{-74}:\\ \;\;\;\;x \cdot y - x\\ \mathbf{elif}\;y \leq 2.16 \cdot 10^{-10}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 1:\\ \;\;\;\;x \cdot \left(y + -1\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error29.84%
Cost656
\[\begin{array}{l} \mathbf{if}\;y \leq -2.3 \cdot 10^{+138}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq -1.8 \cdot 10^{+122}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;y \leq -7.6 \cdot 10^{-13}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 2.5 \cdot 10^{-73}:\\ \;\;\;\;-x\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]
Alternative 4
Error15.48%
Cost585
\[\begin{array}{l} \mathbf{if}\;y \leq -1.85 \cdot 10^{-11} \lor \neg \left(y \leq 2.8 \cdot 10^{-74}\right):\\ \;\;\;\;y \cdot \left(x + 1\right)\\ \mathbf{else}:\\ \;\;\;\;-x\\ \end{array} \]
Alternative 5
Error0.02%
Cost448
\[y \cdot \left(x + 1\right) - x \]
Alternative 6
Error29.39%
Cost392
\[\begin{array}{l} \mathbf{if}\;y \leq -7.6 \cdot 10^{-13}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 1.1 \cdot 10^{-73}:\\ \;\;\;\;-x\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]
Alternative 7
Error56.72%
Cost64
\[y \]

Error

Reproduce?

herbie shell --seed 2023121 
(FPCore (x y)
  :name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
  :precision binary64
  (- (* (+ x 1.0) y) x))