Average Error: 0.3 → 0.1
Time: 14.3s
Precision: 64
\[\left(3 \cdot \left(2 - x \cdot 3\right)\right) \cdot x\]
\[\mathsf{fma}\left(x, 6, -9 \cdot {x}^{2}\right)\]
\left(3 \cdot \left(2 - x \cdot 3\right)\right) \cdot x
\mathsf{fma}\left(x, 6, -9 \cdot {x}^{2}\right)
double f(double x) {
        double r574631 = 3.0;
        double r574632 = 2.0;
        double r574633 = x;
        double r574634 = r574633 * r574631;
        double r574635 = r574632 - r574634;
        double r574636 = r574631 * r574635;
        double r574637 = r574636 * r574633;
        return r574637;
}

double f(double x) {
        double r574638 = x;
        double r574639 = 6.0;
        double r574640 = 9.0;
        double r574641 = 2.0;
        double r574642 = pow(r574638, r574641);
        double r574643 = r574640 * r574642;
        double r574644 = -r574643;
        double r574645 = fma(r574638, r574639, r574644);
        return r574645;
}

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 x \cdot 6 + \color{blue}{\left(-9 \cdot {x}^{2}\right)}\]
  8. Using strategy rm
  9. Applied fma-def0.1

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

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

Reproduce

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