Average Error: 0.3 → 0.1
Time: 2.7s
Precision: 64
\[\left(3 \cdot \left(2 - x \cdot 3\right)\right) \cdot x\]
\[\mathsf{fma}\left(6, x, -9 \cdot {x}^{2}\right)\]
\left(3 \cdot \left(2 - x \cdot 3\right)\right) \cdot x
\mathsf{fma}\left(6, x, -9 \cdot {x}^{2}\right)
double f(double x) {
        double r641086 = 3.0;
        double r641087 = 2.0;
        double r641088 = x;
        double r641089 = r641088 * r641086;
        double r641090 = r641087 - r641089;
        double r641091 = r641086 * r641090;
        double r641092 = r641091 * r641088;
        return r641092;
}

double f(double x) {
        double r641093 = 6.0;
        double r641094 = x;
        double r641095 = 9.0;
        double r641096 = 2.0;
        double r641097 = pow(r641094, r641096);
        double r641098 = r641095 * r641097;
        double r641099 = -r641098;
        double r641100 = fma(r641093, r641094, r641099);
        return r641100;
}

Error

Bits error versus x

Target

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

Derivation

  1. Initial program 0.3

    \[\left(3 \cdot \left(2 - x \cdot 3\right)\right) \cdot x\]
  2. Using strategy rm
  3. Applied flip--0.3

    \[\leadsto \left(3 \cdot \color{blue}{\frac{2 \cdot 2 - \left(x \cdot 3\right) \cdot \left(x \cdot 3\right)}{2 + x \cdot 3}}\right) \cdot x\]
  4. Simplified0.3

    \[\leadsto \left(3 \cdot \frac{\color{blue}{\mathsf{fma}\left(3, x, 2\right) \cdot \left(2 - 3 \cdot x\right)}}{2 + x \cdot 3}\right) \cdot x\]
  5. Simplified0.3

    \[\leadsto \left(3 \cdot \frac{\mathsf{fma}\left(3, x, 2\right) \cdot \left(2 - 3 \cdot x\right)}{\color{blue}{\mathsf{fma}\left(3, x, 2\right)}}\right) \cdot x\]
  6. Taylor expanded around 0 0.2

    \[\leadsto \color{blue}{6 \cdot x - 9 \cdot {x}^{2}}\]
  7. Using strategy rm
  8. Applied fma-neg0.1

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

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

Reproduce

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

  :herbie-target
  (- (* 6 x) (* 9 (* x x)))

  (* (* 3 (- 2 (* x 3))) x))