?

Average Error: 0.0 → 0.0
Time: 3.6s
Precision: binary64
Cost: 6848

?

\[x \cdot y + \left(x - 1\right) \cdot z \]
\[\mathsf{fma}\left(x, y, z \cdot \left(x + -1\right)\right) \]
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
(FPCore (x y z) :precision binary64 (fma x y (* z (+ x -1.0))))
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 * (x + -1.0)));
}
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, y, Float64(z * Float64(x + -1.0)))
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 * y + N[(z * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
x \cdot y + \left(x - 1\right) \cdot z
\mathsf{fma}\left(x, y, z \cdot \left(x + -1\right)\right)

Error?

Derivation?

  1. Initial program 0.0

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

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

    [Start]0.0

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

    fma-def [=>]0.0

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

    *-commutative [=>]0.0

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

    sub-neg [=>]0.0

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

    distribute-rgt-in [=>]0.0

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

    remove-double-neg [<=]0.0

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

    distribute-rgt-out [=>]0.0

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

    distribute-neg-in [<=]0.0

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

    *-commutative [<=]0.0

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

    distribute-neg-in [=>]0.0

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

    remove-double-neg [=>]0.0

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

    metadata-eval [=>]0.0

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

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

Alternatives

Alternative 1
Error25.6
Cost852
\[\begin{array}{l} \mathbf{if}\;x \leq -5.2 \cdot 10^{+46}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq -1.5 \cdot 10^{+14}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;x \leq -4.3 \cdot 10^{-107}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 3 \cdot 10^{-130}:\\ \;\;\;\;-z\\ \mathbf{elif}\;x \leq 3 \cdot 10^{+117}:\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;x \cdot z\\ \end{array} \]
Alternative 2
Error0.9
Cost712
\[\begin{array}{l} \mathbf{if}\;x \leq -32000000:\\ \;\;\;\;x \cdot \left(y + z\right)\\ \mathbf{elif}\;x \leq 6.4:\\ \;\;\;\;x \cdot y - z\\ \mathbf{else}:\\ \;\;\;\;x \cdot y + x \cdot z\\ \end{array} \]
Alternative 3
Error14.0
Cost585
\[\begin{array}{l} \mathbf{if}\;x \leq -2.5 \cdot 10^{-105} \lor \neg \left(x \leq 3 \cdot 10^{-130}\right):\\ \;\;\;\;x \cdot \left(y + z\right)\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 4
Error14.0
Cost585
\[\begin{array}{l} \mathbf{if}\;x \leq -9 \cdot 10^{-106} \lor \neg \left(x \leq 3 \cdot 10^{-130}\right):\\ \;\;\;\;x \cdot \left(y + z\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(x + -1\right)\\ \end{array} \]
Alternative 5
Error0.9
Cost585
\[\begin{array}{l} \mathbf{if}\;x \leq -32000000 \lor \neg \left(x \leq 6.4\right):\\ \;\;\;\;x \cdot \left(y + z\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot y - z\\ \end{array} \]
Alternative 6
Error0.0
Cost576
\[z \cdot \left(x + -1\right) + x \cdot y \]
Alternative 7
Error25.9
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -1.55 \cdot 10^{-105}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 3 \cdot 10^{-130}:\\ \;\;\;\;-z\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
Alternative 8
Error0.0
Cost448
\[x \cdot \left(y + z\right) - z \]
Alternative 9
Error34.9
Cost128
\[-z \]

Error

Reproduce?

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