Average Error: 0.3 → 0.1
Time: 6.8s
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 r680926 = 3.0;
        double r680927 = 2.0;
        double r680928 = x;
        double r680929 = r680928 * r680926;
        double r680930 = r680927 - r680929;
        double r680931 = r680926 * r680930;
        double r680932 = r680931 * r680928;
        return r680932;
}

double f(double x) {
        double r680933 = 6.0;
        double r680934 = x;
        double r680935 = 9.0;
        double r680936 = 2.0;
        double r680937 = pow(r680934, r680936);
        double r680938 = r680935 * r680937;
        double r680939 = -r680938;
        double r680940 = fma(r680933, r680934, r680939);
        return r680940;
}

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. Taylor expanded around 0 0.2

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

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

    \[\leadsto x \cdot \color{blue}{\left(6 + \left(-9 \cdot x\right)\right)}\]
  6. Applied distribute-lft-in0.2

    \[\leadsto \color{blue}{x \cdot 6 + x \cdot \left(-9 \cdot x\right)}\]
  7. Simplified0.2

    \[\leadsto \color{blue}{6 \cdot x} + x \cdot \left(-9 \cdot x\right)\]
  8. Simplified0.2

    \[\leadsto 6 \cdot x + \color{blue}{\left(-9 \cdot {x}^{2}\right)}\]
  9. Using strategy rm
  10. Applied fma-def0.1

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

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

Reproduce

herbie shell --seed 2020047 +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))