Average Error: 0.0 → 0.0
Time: 4.1s
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): 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, 0 points decrease in error
    (+.f64 (*.f64 x y) (Rewrite<= distribute-rgt-in_binary64 (*.f64 z (+.f64 x (neg.f64 1))))): 6 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
Error29.3
Cost720
\[\begin{array}{l} \mathbf{if}\;y \leq -312714197767.71985:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq -2.2896688374444176 \cdot 10^{-207}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq 2.2527914048103772 \cdot 10^{-303}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;y \leq 2.618651262408433 \cdot 10^{+59}:\\ \;\;\;\;-z\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \]
Alternative 2
Error1.0
Cost712
\[\begin{array}{l} \mathbf{if}\;x \leq -489738.6868603319:\\ \;\;\;\;\left(y + z\right) \cdot x\\ \mathbf{elif}\;x \leq 1.5634523489170736 \cdot 10^{-6}:\\ \;\;\;\;y \cdot x - z\\ \mathbf{else}:\\ \;\;\;\;y \cdot x + z \cdot x\\ \end{array} \]
Alternative 3
Error17.8
Cost584
\[\begin{array}{l} \mathbf{if}\;y \leq -5975658112521703:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 2.618651262408433 \cdot 10^{+59}:\\ \;\;\;\;z \cdot x - z\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \]
Alternative 4
Error17.1
Cost584
\[\begin{array}{l} \mathbf{if}\;y \leq -5975658112521703:\\ \;\;\;\;\left(y + z\right) \cdot x\\ \mathbf{elif}\;y \leq 2.618651262408433 \cdot 10^{+59}:\\ \;\;\;\;z \cdot x - z\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \]
Alternative 5
Error1.0
Cost584
\[\begin{array}{l} t_0 := \left(y + z\right) \cdot x\\ \mathbf{if}\;x \leq -489738.6868603319:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1.5634523489170736 \cdot 10^{-6}:\\ \;\;\;\;y \cdot x - z\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error24.7
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -66226.2881030687:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;x \leq 1.5634523489170736 \cdot 10^{-6}:\\ \;\;\;\;-z\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 7
Error0.0
Cost448
\[\left(y + z\right) \cdot x - z \]
Alternative 8
Error35.4
Cost128
\[-z \]

Error

Reproduce

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