Average Error: 0.2 → 0.1
Time: 8.8s
Precision: 64
\[\left(3 \cdot \left(2 - x \cdot 3\right)\right) \cdot x\]
\[\mathsf{fma}\left(x, 6, \left(x \cdot 9\right) \cdot \left(-x\right)\right)\]
\left(3 \cdot \left(2 - x \cdot 3\right)\right) \cdot x
\mathsf{fma}\left(x, 6, \left(x \cdot 9\right) \cdot \left(-x\right)\right)
double f(double x) {
        double r29702969 = 3.0;
        double r29702970 = 2.0;
        double r29702971 = x;
        double r29702972 = r29702971 * r29702969;
        double r29702973 = r29702970 - r29702972;
        double r29702974 = r29702969 * r29702973;
        double r29702975 = r29702974 * r29702971;
        return r29702975;
}

double f(double x) {
        double r29702976 = x;
        double r29702977 = 6.0;
        double r29702978 = 9.0;
        double r29702979 = r29702976 * r29702978;
        double r29702980 = -r29702976;
        double r29702981 = r29702979 * r29702980;
        double r29702982 = fma(r29702976, r29702977, r29702981);
        return r29702982;
}

Error

Bits error versus x

Target

Original0.2
Target0.2
Herbie0.1
\[6 \cdot x - 9 \cdot \left(x \cdot x\right)\]

Derivation

  1. Initial program 0.2

    \[\left(3 \cdot \left(2 - x \cdot 3\right)\right) \cdot x\]
  2. Taylor expanded around 0 0.2

    \[\leadsto \color{blue}{6 \cdot x - 9 \cdot {x}^{2}}\]
  3. Simplified0.2

    \[\leadsto \color{blue}{x \cdot 6 - \left(x \cdot x\right) \cdot 9}\]
  4. Using strategy rm
  5. Applied fma-neg0.1

    \[\leadsto \color{blue}{\mathsf{fma}\left(x, 6, -\left(x \cdot x\right) \cdot 9\right)}\]
  6. Using strategy rm
  7. Applied associate-*l*0.1

    \[\leadsto \mathsf{fma}\left(x, 6, -\color{blue}{x \cdot \left(x \cdot 9\right)}\right)\]
  8. Final simplification0.1

    \[\leadsto \mathsf{fma}\left(x, 6, \left(x \cdot 9\right) \cdot \left(-x\right)\right)\]

Reproduce

herbie shell --seed 2019174 +o rules:numerics
(FPCore (x)
  :name "Diagrams.Tangent:$catParam from diagrams-lib-1.3.0.3, E"

  :herbie-target
  (- (* 6.0 x) (* 9.0 (* x x)))

  (* (* 3.0 (- 2.0 (* x 3.0))) x))