Average Error: 0.0 → 0.0
Time: 4.3s
Precision: binary64
Cost: 6784
\[x \cdot y + \left(x - 1\right) \cdot z \]
\[\mathsf{fma}\left(z + y, x, -z\right) \]
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
(FPCore (x y z) :precision binary64 (fma (+ z y) x (- 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((z + y), x, -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(Float64(z + y), x, 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[(N[(z + y), $MachinePrecision] * x + (-z)), $MachinePrecision]
x \cdot y + \left(x - 1\right) \cdot z
\mathsf{fma}\left(z + y, x, -z\right)

Error

Derivation

  1. Initial program 0.0

    \[x \cdot y + \left(x - 1\right) \cdot z \]
  2. Taylor expanded in x around 0 0.0

    \[\leadsto \color{blue}{\left(y + z\right) \cdot x + -1 \cdot z} \]
  3. Simplified0.0

    \[\leadsto \color{blue}{\mathsf{fma}\left(z + y, x, -z\right)} \]
    Proof
    (fma.f64 (+.f64 z y) x (neg.f64 z)): 0 points increase in error, 0 points decrease in error
    (fma.f64 (Rewrite<= +-commutative_binary64 (+.f64 y z)) x (neg.f64 z)): 0 points increase in error, 0 points decrease in error
    (fma.f64 (+.f64 y z) x (Rewrite<= mul-1-neg_binary64 (*.f64 -1 z))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= fma-def_binary64 (+.f64 (*.f64 (+.f64 y z) x) (*.f64 -1 z))): 0 points increase in error, 0 points decrease in error
  4. Final simplification0.0

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

Alternatives

Alternative 1
Error24.4
Cost720
\[\begin{array}{l} \mathbf{if}\;x \leq -1.9 \cdot 10^{+33}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;x \leq -2.7 \cdot 10^{-86}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;x \leq 6 \cdot 10^{-56}:\\ \;\;\;\;-z\\ \mathbf{elif}\;x \leq 1.22 \cdot 10^{+31}:\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 2
Error13.0
Cost585
\[\begin{array}{l} \mathbf{if}\;x \leq -2.6 \cdot 10^{-86} \lor \neg \left(x \leq 2.4 \cdot 10^{-56}\right):\\ \;\;\;\;\left(z + y\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 3
Error13.0
Cost585
\[\begin{array}{l} \mathbf{if}\;x \leq -2 \cdot 10^{-86} \lor \neg \left(x \leq 1.45 \cdot 10^{-55}\right):\\ \;\;\;\;\left(z + y\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(x + -1\right)\\ \end{array} \]
Alternative 4
Error1.0
Cost585
\[\begin{array}{l} \mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1\right):\\ \;\;\;\;\left(z + y\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;y \cdot x - z\\ \end{array} \]
Alternative 5
Error24.3
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -2.7 \cdot 10^{-86}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;x \leq 2.4 \cdot 10^{-56}:\\ \;\;\;\;-z\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \]
Alternative 6
Error0.0
Cost448
\[\left(z + y\right) \cdot x - z \]
Alternative 7
Error35.1
Cost128
\[-z \]

Error

Reproduce

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