Average Error: 45.2 → 8.3
Time: 20.5s
Precision: 64
\[\mathsf{fma}\left(x, y, z\right) - \left(1 + \left(x \cdot y + z\right)\right)\]
\[\left(\mathsf{fma}\left(x, y, z\right) - \left(z + x \cdot y\right)\right) - 1\]
\mathsf{fma}\left(x, y, z\right) - \left(1 + \left(x \cdot y + z\right)\right)
\left(\mathsf{fma}\left(x, y, z\right) - \left(z + x \cdot y\right)\right) - 1
double f(double x, double y, double z) {
        double r7662596 = x;
        double r7662597 = y;
        double r7662598 = z;
        double r7662599 = fma(r7662596, r7662597, r7662598);
        double r7662600 = 1.0;
        double r7662601 = r7662596 * r7662597;
        double r7662602 = r7662601 + r7662598;
        double r7662603 = r7662600 + r7662602;
        double r7662604 = r7662599 - r7662603;
        return r7662604;
}

double f(double x, double y, double z) {
        double r7662605 = x;
        double r7662606 = y;
        double r7662607 = z;
        double r7662608 = fma(r7662605, r7662606, r7662607);
        double r7662609 = r7662605 * r7662606;
        double r7662610 = r7662607 + r7662609;
        double r7662611 = r7662608 - r7662610;
        double r7662612 = 1.0;
        double r7662613 = r7662611 - r7662612;
        return r7662613;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original45.2
Target0
Herbie8.3
\[-1\]

Derivation

  1. Initial program 45.2

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

    \[\leadsto \mathsf{fma}\left(x, y, z\right) - \color{blue}{\log \left(e^{1 + \left(x \cdot y + z\right)}\right)}\]
  4. Applied add-log-exp47.4

    \[\leadsto \color{blue}{\log \left(e^{\mathsf{fma}\left(x, y, z\right)}\right)} - \log \left(e^{1 + \left(x \cdot y + z\right)}\right)\]
  5. Applied diff-log47.4

    \[\leadsto \color{blue}{\log \left(\frac{e^{\mathsf{fma}\left(x, y, z\right)}}{e^{1 + \left(x \cdot y + z\right)}}\right)}\]
  6. Simplified13.6

    \[\leadsto \log \color{blue}{\left(\frac{e^{\left(\mathsf{fma}\left(x, y, z\right) - x \cdot y\right) - z}}{e}\right)}\]
  7. Using strategy rm
  8. Applied log-div13.6

    \[\leadsto \color{blue}{\log \left(e^{\left(\mathsf{fma}\left(x, y, z\right) - x \cdot y\right) - z}\right) - \log e}\]
  9. Simplified8.3

    \[\leadsto \color{blue}{\left(\mathsf{fma}\left(x, y, z\right) - \left(x \cdot y + z\right)\right)} - \log e\]
  10. Final simplification8.3

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

Reproduce

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

  :herbie-target
  -1

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