Average Error: 45.4 → 15.1
Time: 2.8s
Precision: 64
\[\mathsf{fma}\left(x, y, z\right) - \left(1 + \left(x \cdot y + z\right)\right)\]
\[\left(\left(\mathsf{fma}\left(x, y, z\right) - z\right) - x \cdot y\right) - 1\]
\mathsf{fma}\left(x, y, z\right) - \left(1 + \left(x \cdot y + z\right)\right)
\left(\left(\mathsf{fma}\left(x, y, z\right) - z\right) - x \cdot y\right) - 1
double f(double x, double y, double z) {
        double r46751 = x;
        double r46752 = y;
        double r46753 = z;
        double r46754 = fma(r46751, r46752, r46753);
        double r46755 = 1.0;
        double r46756 = r46751 * r46752;
        double r46757 = r46756 + r46753;
        double r46758 = r46755 + r46757;
        double r46759 = r46754 - r46758;
        return r46759;
}

double f(double x, double y, double z) {
        double r46760 = x;
        double r46761 = y;
        double r46762 = z;
        double r46763 = fma(r46760, r46761, r46762);
        double r46764 = r46763 - r46762;
        double r46765 = r46760 * r46761;
        double r46766 = r46764 - r46765;
        double r46767 = 1.0;
        double r46768 = r46766 - r46767;
        return r46768;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original45.4
Target0
Herbie15.1
\[-1\]

Derivation

  1. Initial program 45.4

    \[\mathsf{fma}\left(x, y, z\right) - \left(1 + \left(x \cdot y + z\right)\right)\]
  2. Using strategy rm
  3. Applied flip-+46.1

    \[\leadsto \mathsf{fma}\left(x, y, z\right) - \left(1 + \color{blue}{\frac{\left(x \cdot y\right) \cdot \left(x \cdot y\right) - z \cdot z}{x \cdot y - z}}\right)\]
  4. Taylor expanded around 0 45.4

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

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

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

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

Reproduce

herbie shell --seed 2020065 
(FPCore (x y z)
  :name "simple fma test"
  :precision binary64

  :herbie-target
  -1

  (- (fma x y z) (+ 1 (+ (* x y) z))))