Average Error: 0.3 → 0.1
Time: 34.9s
Precision: 64
\[\left(3 \cdot \left(2 - x \cdot 3\right)\right) \cdot x\]
\[\mathsf{fma}\left(6, x, \left(9 \cdot x\right) \cdot \left(-x\right)\right)\]
\left(3 \cdot \left(2 - x \cdot 3\right)\right) \cdot x
\mathsf{fma}\left(6, x, \left(9 \cdot x\right) \cdot \left(-x\right)\right)
double f(double x) {
        double r32029358 = 3.0;
        double r32029359 = 2.0;
        double r32029360 = x;
        double r32029361 = r32029360 * r32029358;
        double r32029362 = r32029359 - r32029361;
        double r32029363 = r32029358 * r32029362;
        double r32029364 = r32029363 * r32029360;
        return r32029364;
}

double f(double x) {
        double r32029365 = 6.0;
        double r32029366 = x;
        double r32029367 = 9.0;
        double r32029368 = r32029367 * r32029366;
        double r32029369 = -r32029366;
        double r32029370 = r32029368 * r32029369;
        double r32029371 = fma(r32029365, r32029366, r32029370);
        return r32029371;
}

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-rgt-in0.2

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

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

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

Reproduce

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