Average Error: 0.1 → 0.1
Time: 16.9s
Precision: 64
\[3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right)\]
\[\mathsf{fma}\left(x, \mathsf{fma}\left(x, 9, -12\right), 3\right)\]
3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right)
\mathsf{fma}\left(x, \mathsf{fma}\left(x, 9, -12\right), 3\right)
double f(double x) {
        double r507500 = 3.0;
        double r507501 = x;
        double r507502 = r507501 * r507500;
        double r507503 = r507502 * r507501;
        double r507504 = 4.0;
        double r507505 = r507501 * r507504;
        double r507506 = r507503 - r507505;
        double r507507 = 1.0;
        double r507508 = r507506 + r507507;
        double r507509 = r507500 * r507508;
        return r507509;
}

double f(double x) {
        double r507510 = x;
        double r507511 = 9.0;
        double r507512 = 12.0;
        double r507513 = -r507512;
        double r507514 = fma(r507510, r507511, r507513);
        double r507515 = 3.0;
        double r507516 = fma(r507510, r507514, r507515);
        return r507516;
}

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

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

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

Reproduce

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