Average Error: 0.1 → 0.1
Time: 14.2s
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 r480480 = 3.0;
        double r480481 = x;
        double r480482 = r480481 * r480480;
        double r480483 = r480482 * r480481;
        double r480484 = 4.0;
        double r480485 = r480481 * r480484;
        double r480486 = r480483 - r480485;
        double r480487 = 1.0;
        double r480488 = r480486 + r480487;
        double r480489 = r480480 * r480488;
        return r480489;
}

double f(double x) {
        double r480490 = x;
        double r480491 = 9.0;
        double r480492 = 12.0;
        double r480493 = -r480492;
        double r480494 = fma(r480490, r480491, r480493);
        double r480495 = 3.0;
        double r480496 = fma(r480490, r480494, r480495);
        return r480496;
}

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 2019323 +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)))