Average Error: 0.3 → 0.1
Time: 14.0s
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 r500705 = 3.0;
        double r500706 = 2.0;
        double r500707 = x;
        double r500708 = r500707 * r500705;
        double r500709 = r500706 - r500708;
        double r500710 = r500705 * r500709;
        double r500711 = r500710 * r500707;
        return r500711;
}

double f(double x) {
        double r500712 = x;
        double r500713 = 6.0;
        double r500714 = 9.0;
        double r500715 = 2.0;
        double r500716 = pow(r500712, r500715);
        double r500717 = r500714 * r500716;
        double r500718 = -r500717;
        double r500719 = fma(r500712, r500713, r500718);
        return r500719;
}

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))