Average Error: 0.1 → 0.0
Time: 26.8s
Precision: 64
\[x \cdot \left(y + z\right) + z \cdot 5\]
\[\mathsf{fma}\left(z, x + 5, y \cdot x\right)\]
x \cdot \left(y + z\right) + z \cdot 5
\mathsf{fma}\left(z, x + 5, y \cdot x\right)
double f(double x, double y, double z) {
        double r22845272 = x;
        double r22845273 = y;
        double r22845274 = z;
        double r22845275 = r22845273 + r22845274;
        double r22845276 = r22845272 * r22845275;
        double r22845277 = 5.0;
        double r22845278 = r22845274 * r22845277;
        double r22845279 = r22845276 + r22845278;
        return r22845279;
}

double f(double x, double y, double z) {
        double r22845280 = z;
        double r22845281 = x;
        double r22845282 = 5.0;
        double r22845283 = r22845281 + r22845282;
        double r22845284 = y;
        double r22845285 = r22845284 * r22845281;
        double r22845286 = fma(r22845280, r22845283, r22845285);
        return r22845286;
}

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. Simplified0.1

    \[\leadsto \color{blue}{\mathsf{fma}\left(x, z + y, 5 \cdot z\right)}\]
  3. Taylor expanded around 0 0.1

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

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

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

Reproduce

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