Average Error: 0.1 → 0.0
Time: 5.8s
Precision: 64
\[x \cdot \left(y + z\right) + z \cdot 5\]
\[\mathsf{fma}\left(z, 5, \left(z + y\right) \cdot x\right)\]
x \cdot \left(y + z\right) + z \cdot 5
\mathsf{fma}\left(z, 5, \left(z + y\right) \cdot x\right)
double f(double x, double y, double z) {
        double r23696334 = x;
        double r23696335 = y;
        double r23696336 = z;
        double r23696337 = r23696335 + r23696336;
        double r23696338 = r23696334 * r23696337;
        double r23696339 = 5.0;
        double r23696340 = r23696336 * r23696339;
        double r23696341 = r23696338 + r23696340;
        return r23696341;
}

double f(double x, double y, double z) {
        double r23696342 = z;
        double r23696343 = 5.0;
        double r23696344 = y;
        double r23696345 = r23696342 + r23696344;
        double r23696346 = x;
        double r23696347 = r23696345 * r23696346;
        double r23696348 = fma(r23696342, r23696343, r23696347);
        return r23696348;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

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

Derivation

  1. Initial program 0.1

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

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

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

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

Reproduce

herbie shell --seed 2019192 +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)))