?

Average Accuracy: 100.0% → 100.0%
Time: 4.7s
Precision: binary64
Cost: 6784

?

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

Error?

Derivation?

  1. Initial program 100.0%

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

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

    [Start]100.0

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

    *-commutative [=>]100.0

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

    sub-neg [=>]100.0

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

    distribute-rgt-in [=>]100.0

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

    associate-+r+ [=>]100.0

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

    distribute-lft-out [=>]100.0

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

    fma-def [=>]100.0

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

    metadata-eval [=>]100.0

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

    mul-1-neg [=>]100.0

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

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

Alternatives

Alternative 1
Accuracy81.0%
Cost585
\[\begin{array}{l} \mathbf{if}\;x \leq -7 \cdot 10^{-14} \lor \neg \left(x \leq 1.85 \cdot 10^{-6}\right):\\ \;\;\;\;x \cdot \left(y + z\right)\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 2
Accuracy98.2%
Cost585
\[\begin{array}{l} \mathbf{if}\;x \leq -58000000000000 \lor \neg \left(x \leq 7.5 \cdot 10^{-5}\right):\\ \;\;\;\;x \cdot \left(y + z\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot y - z\\ \end{array} \]
Alternative 3
Accuracy62.6%
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -4.2 \cdot 10^{-14}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 3.3 \cdot 10^{-6}:\\ \;\;\;\;-z\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
Alternative 4
Accuracy63.4%
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -6.2 \cdot 10^{-14}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 1:\\ \;\;\;\;-z\\ \mathbf{else}:\\ \;\;\;\;x \cdot z\\ \end{array} \]
Alternative 5
Accuracy100.0%
Cost448
\[x \cdot \left(y + z\right) - z \]
Alternative 6
Accuracy45.6%
Cost128
\[-z \]

Error

Reproduce?

herbie shell --seed 2023151 
(FPCore (x y z)
  :name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
  :precision binary64
  (+ (* x y) (* (- x 1.0) z)))