Average Error: 0.1 → 0.1
Time: 2.2s
Precision: 64
\[3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right)\]
\[\mathsf{fma}\left({x}^{2}, 9, 3 - 12 \cdot x\right)\]
3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right)
\mathsf{fma}\left({x}^{2}, 9, 3 - 12 \cdot x\right)
double f(double x) {
        double r656620 = 3.0;
        double r656621 = x;
        double r656622 = r656621 * r656620;
        double r656623 = r656622 * r656621;
        double r656624 = 4.0;
        double r656625 = r656621 * r656624;
        double r656626 = r656623 - r656625;
        double r656627 = 1.0;
        double r656628 = r656626 + r656627;
        double r656629 = r656620 * r656628;
        return r656629;
}

double f(double x) {
        double r656630 = x;
        double r656631 = 2.0;
        double r656632 = pow(r656630, r656631);
        double r656633 = 9.0;
        double r656634 = 3.0;
        double r656635 = 12.0;
        double r656636 = r656635 * r656630;
        double r656637 = r656634 - r656636;
        double r656638 = fma(r656632, r656633, r656637);
        return r656638;
}

Error

Bits error versus x

Target

Original0.1
Target0.1
Herbie0.1
\[3 + \left(\left(9 \cdot x\right) \cdot x - 12 \cdot x\right)\]

Derivation

  1. Initial program 0.1

    \[3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right)\]
  2. Taylor expanded around 0 0.1

    \[\leadsto \color{blue}{\left(9 \cdot {x}^{2} + 3\right) - 12 \cdot x}\]
  3. Simplified0.1

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

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

Reproduce

herbie shell --seed 2019354 +o rules:numerics
(FPCore (x)
  :name "Diagrams.Tangent:$catParam from diagrams-lib-1.3.0.3, D"
  :precision binary64

  :herbie-target
  (+ 3 (- (* (* 9 x) x) (* 12 x)))

  (* 3 (+ (- (* (* x 3) x) (* x 4)) 1)))