?

Average Error: 0.03% → 0.02%
Time: 4.0s
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.03

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

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

    [Start]0.03

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

    fma-def [=>]0.02

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

    *-commutative [=>]0.02

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

    sub-neg [=>]0.02

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

    distribute-rgt-in [=>]0.02

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

    remove-double-neg [<=]0.02

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

    distribute-rgt-out [=>]0.02

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

    distribute-neg-in [<=]0.02

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

    *-commutative [<=]0.02

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

    distribute-neg-in [=>]0.02

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

    remove-double-neg [=>]0.02

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

    metadata-eval [=>]0.02

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

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

Alternatives

Alternative 1
Error39.09%
Cost1116
\[\begin{array}{l} \mathbf{if}\;x \leq -2.9 \cdot 10^{-31}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq -2.3 \cdot 10^{-146}:\\ \;\;\;\;-z\\ \mathbf{elif}\;x \leq -8.8 \cdot 10^{-159}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 2.6 \cdot 10^{-126}:\\ \;\;\;\;-z\\ \mathbf{elif}\;x \leq 2.3 \cdot 10^{-68}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 1.08 \cdot 10^{-29}:\\ \;\;\;\;-z\\ \mathbf{elif}\;x \leq 7.8 \cdot 10^{+152}:\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;x \cdot z\\ \end{array} \]
Alternative 2
Error21.76%
Cost1112
\[\begin{array}{l} t_0 := x \cdot \left(y + z\right)\\ \mathbf{if}\;x \leq -1.6 \cdot 10^{-32}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -3.2 \cdot 10^{-146}:\\ \;\;\;\;-z\\ \mathbf{elif}\;x \leq -8.8 \cdot 10^{-159}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 2.7 \cdot 10^{-127}:\\ \;\;\;\;-z\\ \mathbf{elif}\;x \leq 4.7 \cdot 10^{-70}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 1.08 \cdot 10^{-29}:\\ \;\;\;\;-z\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error21.51%
Cost1112
\[\begin{array}{l} t_0 := x \cdot \left(y + z\right)\\ \mathbf{if}\;x \leq -1:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -2.3 \cdot 10^{-146}:\\ \;\;\;\;z \cdot \left(x + -1\right)\\ \mathbf{elif}\;x \leq -8.8 \cdot 10^{-159}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 2.6 \cdot 10^{-126}:\\ \;\;\;\;-z\\ \mathbf{elif}\;x \leq 3 \cdot 10^{-69}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 1.08 \cdot 10^{-29}:\\ \;\;\;\;-z\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error39.42%
Cost986
\[\begin{array}{l} \mathbf{if}\;x \leq -5.6 \cdot 10^{-32}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq -2.3 \cdot 10^{-146} \lor \neg \left(x \leq -8.8 \cdot 10^{-159}\right) \land \left(x \leq 2.6 \cdot 10^{-126} \lor \neg \left(x \leq 4.2 \cdot 10^{-69}\right) \land x \leq 7 \cdot 10^{-30}\right):\\ \;\;\;\;-z\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
Alternative 5
Error1.86%
Cost585
\[\begin{array}{l} \mathbf{if}\;x \leq -7.4 \cdot 10^{+16} \lor \neg \left(x \leq 1\right):\\ \;\;\;\;x \cdot \left(y + z\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot y - z\\ \end{array} \]
Alternative 6
Error0.02%
Cost448
\[x \cdot \left(y + z\right) - z \]
Alternative 7
Error54.07%
Cost128
\[-z \]

Error

Reproduce?

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