Average Error: 0.2 → 0.1
Time: 2.2s
Precision: 64
\[\left(3 \cdot \left(2 - x \cdot 3\right)\right) \cdot x\]
\[\mathsf{fma}\left(x, 6, x \cdot \left(-9 \cdot x\right)\right)\]
\left(3 \cdot \left(2 - x \cdot 3\right)\right) \cdot x
\mathsf{fma}\left(x, 6, x \cdot \left(-9 \cdot x\right)\right)
double f(double x) {
        double r625148 = 3.0;
        double r625149 = 2.0;
        double r625150 = x;
        double r625151 = r625150 * r625148;
        double r625152 = r625149 - r625151;
        double r625153 = r625148 * r625152;
        double r625154 = r625153 * r625150;
        return r625154;
}

double f(double x) {
        double r625155 = x;
        double r625156 = 6.0;
        double r625157 = 9.0;
        double r625158 = r625157 * r625155;
        double r625159 = -r625158;
        double r625160 = r625155 * r625159;
        double r625161 = fma(r625155, r625156, r625160);
        return r625161;
}

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 \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. Using strategy rm
  8. Applied fma-def0.1

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

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

Reproduce

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