Average Error: 45.4 → 8.2
Time: 34.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 r6785393 = x;
        double r6785394 = y;
        double r6785395 = z;
        double r6785396 = fma(r6785393, r6785394, r6785395);
        double r6785397 = 1.0;
        double r6785398 = r6785393 * r6785394;
        double r6785399 = r6785398 + r6785395;
        double r6785400 = r6785397 + r6785399;
        double r6785401 = r6785396 - r6785400;
        return r6785401;
}

double f(double x, double y, double z) {
        double r6785402 = x;
        double r6785403 = y;
        double r6785404 = z;
        double r6785405 = fma(r6785402, r6785403, r6785404);
        double r6785406 = r6785402 * r6785403;
        double r6785407 = r6785404 + r6785406;
        double r6785408 = r6785405 - r6785407;
        double r6785409 = 1.0;
        double r6785410 = r6785408 - r6785409;
        return r6785410;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original45.4
Target0
Herbie8.2
\[-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 add-log-exp46.4

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

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

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

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

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

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

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

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

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

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

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

Reproduce

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

  :herbie-target
  -1

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