Average Error: 0.1 → 0.1
Time: 13.1s
Precision: 64
\[3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right)\]
\[\mathsf{fma}\left(-12, x, \mathsf{fma}\left(x, x \cdot 9, 3\right)\right)\]
3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right)
\mathsf{fma}\left(-12, x, \mathsf{fma}\left(x, x \cdot 9, 3\right)\right)
double f(double x) {
        double r660760 = 3.0;
        double r660761 = x;
        double r660762 = r660761 * r660760;
        double r660763 = r660762 * r660761;
        double r660764 = 4.0;
        double r660765 = r660761 * r660764;
        double r660766 = r660763 - r660765;
        double r660767 = 1.0;
        double r660768 = r660766 + r660767;
        double r660769 = r660760 * r660768;
        return r660769;
}

double f(double x) {
        double r660770 = 12.0;
        double r660771 = -r660770;
        double r660772 = x;
        double r660773 = 9.0;
        double r660774 = r660772 * r660773;
        double r660775 = 3.0;
        double r660776 = fma(r660772, r660774, r660775);
        double r660777 = fma(r660771, r660772, r660776);
        return r660777;
}

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(-12, x, \mathsf{fma}\left(x, x \cdot 9, 3\right)\right)}\]
  4. Final simplification0.1

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

Reproduce

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

  :herbie-target
  (+ 3.0 (- (* (* 9.0 x) x) (* 12.0 x)))

  (* 3.0 (+ (- (* (* x 3.0) x) (* x 4.0)) 1.0)))