Average Error: 0.2 → 0.1
Time: 3.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 r718468 = 3.0;
        double r718469 = x;
        double r718470 = r718469 * r718468;
        double r718471 = r718470 * r718469;
        double r718472 = 4.0;
        double r718473 = r718469 * r718472;
        double r718474 = r718471 - r718473;
        double r718475 = 1.0;
        double r718476 = r718474 + r718475;
        double r718477 = r718468 * r718476;
        return r718477;
}

double f(double x) {
        double r718478 = x;
        double r718479 = 9.0;
        double r718480 = r718479 * r718478;
        double r718481 = 12.0;
        double r718482 = r718480 - r718481;
        double r718483 = 3.0;
        double r718484 = fma(r718478, r718482, r718483);
        return r718484;
}

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. Simplified0.1

    \[\leadsto \color{blue}{\mathsf{fma}\left(x, x \cdot 3 - 4, 1\right) \cdot 3}\]
  3. Taylor expanded around 0 0.1

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

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

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

Reproduce

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