Average Error: 44.6 → 7.8
Time: 1.0m
Precision: 64
\[\mathsf{fma}\left(x, y, z\right) - \left(1 + \left(x \cdot y + z\right)\right)\]
\[-1 + \left(\mathsf{fma}\left(x, y, z\right) - \left(z + x \cdot y\right)\right)\]
\mathsf{fma}\left(x, y, z\right) - \left(1 + \left(x \cdot y + z\right)\right)
-1 + \left(\mathsf{fma}\left(x, y, z\right) - \left(z + x \cdot y\right)\right)
double f(double x, double y, double z) {
        double r12429695 = x;
        double r12429696 = y;
        double r12429697 = z;
        double r12429698 = fma(r12429695, r12429696, r12429697);
        double r12429699 = 1.0;
        double r12429700 = r12429695 * r12429696;
        double r12429701 = r12429700 + r12429697;
        double r12429702 = r12429699 + r12429701;
        double r12429703 = r12429698 - r12429702;
        return r12429703;
}

double f(double x, double y, double z) {
        double r12429704 = -1.0;
        double r12429705 = x;
        double r12429706 = y;
        double r12429707 = z;
        double r12429708 = fma(r12429705, r12429706, r12429707);
        double r12429709 = r12429705 * r12429706;
        double r12429710 = r12429707 + r12429709;
        double r12429711 = r12429708 - r12429710;
        double r12429712 = r12429704 + r12429711;
        return r12429712;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original44.6
Target0
Herbie7.8
\[-1\]

Derivation

  1. Initial program 44.6

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Reproduce

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

  :herbie-target
  -1

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