Average Error: 0.1 → 0.0
Time: 13.2s
Precision: 64
\[x \cdot \left(y + z\right) + z \cdot 5.0\]
\[\mathsf{fma}\left(5.0, z, \left(z + y\right) \cdot x\right)\]
x \cdot \left(y + z\right) + z \cdot 5.0
\mathsf{fma}\left(5.0, z, \left(z + y\right) \cdot x\right)
double f(double x, double y, double z) {
        double r23410613 = x;
        double r23410614 = y;
        double r23410615 = z;
        double r23410616 = r23410614 + r23410615;
        double r23410617 = r23410613 * r23410616;
        double r23410618 = 5.0;
        double r23410619 = r23410615 * r23410618;
        double r23410620 = r23410617 + r23410619;
        return r23410620;
}

double f(double x, double y, double z) {
        double r23410621 = 5.0;
        double r23410622 = z;
        double r23410623 = y;
        double r23410624 = r23410622 + r23410623;
        double r23410625 = x;
        double r23410626 = r23410624 * r23410625;
        double r23410627 = fma(r23410621, r23410622, r23410626);
        return r23410627;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original0.1
Target0.1
Herbie0.0
\[\left(x + 5.0\right) \cdot z + x \cdot y\]

Derivation

  1. Initial program 0.1

    \[x \cdot \left(y + z\right) + z \cdot 5.0\]
  2. Taylor expanded around 0 0.1

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

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

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

Reproduce

herbie shell --seed 2019162 +o rules:numerics
(FPCore (x y z)
  :name "Graphics.Rendering.Plot.Render.Plot.Legend:renderLegendOutside from plot-0.2.3.4, C"

  :herbie-target
  (+ (* (+ x 5.0) z) (* x y))

  (+ (* x (+ y z)) (* z 5.0)))