Average Error: 45.1 → 7.8
Time: 33.9s
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 r5271302 = x;
        double r5271303 = y;
        double r5271304 = z;
        double r5271305 = fma(r5271302, r5271303, r5271304);
        double r5271306 = 1.0;
        double r5271307 = r5271302 * r5271303;
        double r5271308 = r5271307 + r5271304;
        double r5271309 = r5271306 + r5271308;
        double r5271310 = r5271305 - r5271309;
        return r5271310;
}

double f(double x, double y, double z) {
        double r5271311 = x;
        double r5271312 = y;
        double r5271313 = z;
        double r5271314 = fma(r5271311, r5271312, r5271313);
        double r5271315 = r5271311 * r5271312;
        double r5271316 = r5271313 + r5271315;
        double r5271317 = r5271314 - r5271316;
        double r5271318 = 1.0;
        double r5271319 = r5271317 - r5271318;
        return r5271319;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original45.1
Target0
Herbie7.8
\[-1\]

Derivation

  1. Initial program 45.1

    \[\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.0

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

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

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

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

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

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

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

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

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

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

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

Reproduce

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

  :herbie-target
  -1

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