Average Error: 0.2 → 0.1
Time: 9.2s
Precision: 64
\[\left(3 \cdot \left(2 - x \cdot 3\right)\right) \cdot x\]
\[\mathsf{fma}\left(6, x, -x \cdot \left(x \cdot 9\right)\right)\]
\left(3 \cdot \left(2 - x \cdot 3\right)\right) \cdot x
\mathsf{fma}\left(6, x, -x \cdot \left(x \cdot 9\right)\right)
double f(double x) {
        double r43660339 = 3.0;
        double r43660340 = 2.0;
        double r43660341 = x;
        double r43660342 = r43660341 * r43660339;
        double r43660343 = r43660340 - r43660342;
        double r43660344 = r43660339 * r43660343;
        double r43660345 = r43660344 * r43660341;
        return r43660345;
}

double f(double x) {
        double r43660346 = 6.0;
        double r43660347 = x;
        double r43660348 = 9.0;
        double r43660349 = r43660347 * r43660348;
        double r43660350 = r43660347 * r43660349;
        double r43660351 = -r43660350;
        double r43660352 = fma(r43660346, r43660347, r43660351);
        return r43660352;
}

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}{6 \cdot x - \left(x \cdot x\right) \cdot 9}\]
  4. Using strategy rm
  5. Applied fma-neg0.1

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

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

    \[\leadsto \mathsf{fma}\left(6, x, -x \cdot \left(x \cdot 9\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))