Average Error: 0.1 → 0.1
Time: 3.0s
Precision: 64
\[x \cdot \left(y + z\right) + z \cdot 5\]
\[\mathsf{fma}\left(5, z, x \cdot y\right) + x \cdot z\]
x \cdot \left(y + z\right) + z \cdot 5
\mathsf{fma}\left(5, z, x \cdot y\right) + x \cdot z
double f(double x, double y, double z) {
        double r495427 = x;
        double r495428 = y;
        double r495429 = z;
        double r495430 = r495428 + r495429;
        double r495431 = r495427 * r495430;
        double r495432 = 5.0;
        double r495433 = r495429 * r495432;
        double r495434 = r495431 + r495433;
        return r495434;
}

double f(double x, double y, double z) {
        double r495435 = 5.0;
        double r495436 = z;
        double r495437 = x;
        double r495438 = y;
        double r495439 = r495437 * r495438;
        double r495440 = fma(r495435, r495436, r495439);
        double r495441 = r495437 * r495436;
        double r495442 = r495440 + r495441;
        return r495442;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original0.1
Target0.1
Herbie0.1
\[\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. Using strategy rm
  3. Applied *-un-lft-identity0.1

    \[\leadsto \color{blue}{\left(1 \cdot x\right)} \cdot \left(y + z\right) + z \cdot 5\]
  4. Applied associate-*l*0.1

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

    \[\leadsto 1 \cdot \color{blue}{\mathsf{fma}\left(x, z, x \cdot y\right)} + z \cdot 5\]
  6. Using strategy rm
  7. Applied fma-udef0.1

    \[\leadsto 1 \cdot \color{blue}{\left(x \cdot z + x \cdot y\right)} + z \cdot 5\]
  8. Applied distribute-lft-in0.1

    \[\leadsto \color{blue}{\left(1 \cdot \left(x \cdot z\right) + 1 \cdot \left(x \cdot y\right)\right)} + z \cdot 5\]
  9. Applied associate-+l+0.1

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

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

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

Reproduce

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

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

  (+ (* x (+ y z)) (* z 5)))