Average Error: 0.2 → 0.1
Time: 2.0s
Precision: 64
\[3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right)\]
\[\mathsf{fma}\left(x, 9 \cdot x - 12, 3\right)\]
3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right)
\mathsf{fma}\left(x, 9 \cdot x - 12, 3\right)
double f(double x) {
        double r685107 = 3.0;
        double r685108 = x;
        double r685109 = r685108 * r685107;
        double r685110 = r685109 * r685108;
        double r685111 = 4.0;
        double r685112 = r685108 * r685111;
        double r685113 = r685110 - r685112;
        double r685114 = 1.0;
        double r685115 = r685113 + r685114;
        double r685116 = r685107 * r685115;
        return r685116;
}

double f(double x) {
        double r685117 = x;
        double r685118 = 9.0;
        double r685119 = r685118 * r685117;
        double r685120 = 12.0;
        double r685121 = r685119 - r685120;
        double r685122 = 3.0;
        double r685123 = fma(r685117, r685121, r685122);
        return r685123;
}

Error

Bits error versus x

Target

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

Derivation

  1. Initial program 0.2

    \[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. Taylor expanded around 0 0.1

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

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

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

Reproduce

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