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

Error

Derivation

  1. Initial program 0.0

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

    \[\leadsto \color{blue}{x \cdot \left(y + z\right) - z} \]
    Proof
    (-.f64 (*.f64 x (+.f64 y z)) z): 0 points increase in error, 0 points decrease in error
    (-.f64 (Rewrite<= distribute-lft-out_binary64 (+.f64 (*.f64 x y) (*.f64 x z))) z): 2 points increase in error, 3 points decrease in error
    (Rewrite<= unsub-neg_binary64 (+.f64 (+.f64 (*.f64 x y) (*.f64 x z)) (neg.f64 z))): 0 points increase in error, 0 points decrease in error
    (+.f64 (+.f64 (*.f64 x y) (*.f64 x z)) (Rewrite<= mul-1-neg_binary64 (*.f64 -1 z))): 0 points increase in error, 0 points decrease in error
    (+.f64 (+.f64 (*.f64 x y) (*.f64 x z)) (*.f64 (Rewrite<= metadata-eval (neg.f64 1)) z)): 0 points increase in error, 0 points decrease in error
    (Rewrite<= associate-+r+_binary64 (+.f64 (*.f64 x y) (+.f64 (*.f64 x z) (*.f64 (neg.f64 1) z)))): 0 points increase in error, 1 points decrease in error
    (+.f64 (*.f64 x y) (Rewrite<= distribute-rgt-in_binary64 (*.f64 z (+.f64 x (neg.f64 1))))): 4 points increase in error, 2 points decrease in error
    (+.f64 (*.f64 x y) (*.f64 z (Rewrite<= sub-neg_binary64 (-.f64 x 1)))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 x y) (Rewrite<= *-commutative_binary64 (*.f64 (-.f64 x 1) z))): 0 points increase in error, 0 points decrease in error
  3. Applied egg-rr0.0

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

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

Alternatives

Alternative 1
Error24.1
Cost984
\[\begin{array}{l} \mathbf{if}\;x \leq -3.35 \cdot 10^{+189}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;x \leq -2.1 \cdot 10^{+134}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;x \leq -5.867747587884991 \cdot 10^{-19}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;x \leq -9.717088850848691 \cdot 10^{-141}:\\ \;\;\;\;-z\\ \mathbf{elif}\;x \leq -1.8598063871050298 \cdot 10^{-174}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;x \leq 7.437725542128105 \cdot 10^{-10}:\\ \;\;\;\;-z\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \]
Alternative 2
Error13.2
Cost848
\[\begin{array}{l} t_0 := x \cdot \left(y + z\right)\\ \mathbf{if}\;x \leq -9.713037785339045 \cdot 10^{-43}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -9.717088850848691 \cdot 10^{-141}:\\ \;\;\;\;-z\\ \mathbf{elif}\;x \leq -1.8598063871050298 \cdot 10^{-174}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;x \leq 7.437725542128105 \cdot 10^{-10}:\\ \;\;\;\;-z\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error24.2
Cost720
\[\begin{array}{l} \mathbf{if}\;x \leq -5.867747587884991 \cdot 10^{-19}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;x \leq -9.717088850848691 \cdot 10^{-141}:\\ \;\;\;\;-z\\ \mathbf{elif}\;x \leq -1.8598063871050298 \cdot 10^{-174}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;x \leq 7.437725542128105 \cdot 10^{-10}:\\ \;\;\;\;-z\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \]
Alternative 4
Error1.0
Cost584
\[\begin{array}{l} t_0 := x \cdot \left(y + z\right)\\ \mathbf{if}\;x \leq -76.55260091418698:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 7.437725542128105 \cdot 10^{-10}:\\ \;\;\;\;y \cdot x - z\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error1.0
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -76.55260091418698:\\ \;\;\;\;x \cdot z + y \cdot x\\ \mathbf{elif}\;x \leq 7.437725542128105 \cdot 10^{-10}:\\ \;\;\;\;y \cdot x - z\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(y + z\right)\\ \end{array} \]
Alternative 6
Error0.0
Cost576
\[\left(x \cdot z - z\right) + y \cdot x \]
Alternative 7
Error0.0
Cost448
\[x \cdot \left(y + z\right) - z \]
Alternative 8
Error34.7
Cost128
\[-z \]

Error

Reproduce

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