Average Error: 0.0 → 0.0
Time: 3.3s
Precision: binary64
Cost: 6784
\[x \cdot y + \left(x - 1\right) \cdot z \]
\[\mathsf{fma}\left(y + z, x, -z\right) \]
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
(FPCore (x y z) :precision binary64 (fma (+ y z) 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((y + z), 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(y + z), 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[(y + z), $MachinePrecision] * x + (-z)), $MachinePrecision]
x \cdot y + \left(x - 1\right) \cdot z
\mathsf{fma}\left(y + z, x, -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): 1 points increase in error, 2 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, 0 points decrease in error
    (+.f64 (*.f64 x y) (Rewrite<= distribute-rgt-in_binary64 (*.f64 z (+.f64 x (neg.f64 1))))): 1 points increase in error, 0 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 + z, x, -z\right)} \]
  4. Final simplification0.0

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

Alternatives

Alternative 1
Error16.9
Cost848
\[\begin{array}{l} t_0 := z \cdot x - z\\ \mathbf{if}\;z \leq -4.422259539747526 \cdot 10^{+27}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -16577504821.054987:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;z \leq -9.534165166519795 \cdot 10^{-159}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 4.979555220151408 \cdot 10^{-148}:\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error11.9
Cost584
\[\begin{array}{l} t_0 := \left(y + z\right) \cdot x\\ \mathbf{if}\;x \leq -1.923311377704013 \cdot 10^{-42}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 0.0008018899533276965:\\ \;\;\;\;z \cdot x - z\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error0.9
Cost584
\[\begin{array}{l} t_0 := \left(y + z\right) \cdot x\\ \mathbf{if}\;x \leq -966.3580826460436:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 0.0008018899533276965:\\ \;\;\;\;y \cdot x - z\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error24.2
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -0.010586985840304172:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;x \leq 2277504396.679781:\\ \;\;\;\;-z\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 5
Error23.1
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -1.923311377704013 \cdot 10^{-42}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;x \leq 9.191320262236147 \cdot 10^{-13}:\\ \;\;\;\;-z\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \]
Alternative 6
Error0.0
Cost448
\[\left(y + z\right) \cdot x - z \]
Alternative 7
Error34.6
Cost128
\[-z \]

Error

Reproduce

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