Average Error: 0.2 → 0.1
Time: 10.4s
Precision: 64
\[\left(x \cdot 3\right) \cdot y - z\]
\[\mathsf{fma}\left(3, y \cdot x, -z\right)\]
\left(x \cdot 3\right) \cdot y - z
\mathsf{fma}\left(3, y \cdot x, -z\right)
double f(double x, double y, double z) {
        double r30495306 = x;
        double r30495307 = 3.0;
        double r30495308 = r30495306 * r30495307;
        double r30495309 = y;
        double r30495310 = r30495308 * r30495309;
        double r30495311 = z;
        double r30495312 = r30495310 - r30495311;
        return r30495312;
}

double f(double x, double y, double z) {
        double r30495313 = 3.0;
        double r30495314 = y;
        double r30495315 = x;
        double r30495316 = r30495314 * r30495315;
        double r30495317 = z;
        double r30495318 = -r30495317;
        double r30495319 = fma(r30495313, r30495316, r30495318);
        return r30495319;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original0.2
Target0.2
Herbie0.1
\[x \cdot \left(3 \cdot y\right) - z\]

Derivation

  1. Initial program 0.2

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

    \[\leadsto \color{blue}{3 \cdot \left(x \cdot y\right)} - z\]
  3. Using strategy rm
  4. Applied fma-neg0.1

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

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

Reproduce

herbie shell --seed 2019172 +o rules:numerics
(FPCore (x y z)
  :name "Diagrams.Solve.Polynomial:cubForm  from diagrams-solve-0.1, B"

  :herbie-target
  (- (* x (* 3.0 y)) z)

  (- (* (* x 3.0) y) z))