Average Error: 0.1 → 0.1
Time: 13.7s
Precision: 64
\[3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right)\]
\[\mathsf{fma}\left(9, x \cdot x, 3 - x \cdot 12\right)\]
3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right)
\mathsf{fma}\left(9, x \cdot x, 3 - x \cdot 12\right)
double f(double x) {
        double r434606 = 3.0;
        double r434607 = x;
        double r434608 = r434607 * r434606;
        double r434609 = r434608 * r434607;
        double r434610 = 4.0;
        double r434611 = r434607 * r434610;
        double r434612 = r434609 - r434611;
        double r434613 = 1.0;
        double r434614 = r434612 + r434613;
        double r434615 = r434606 * r434614;
        return r434615;
}

double f(double x) {
        double r434616 = 9.0;
        double r434617 = x;
        double r434618 = r434617 * r434617;
        double r434619 = 3.0;
        double r434620 = 12.0;
        double r434621 = r434617 * r434620;
        double r434622 = r434619 - r434621;
        double r434623 = fma(r434616, r434618, r434622);
        return r434623;
}

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}{\mathsf{fma}\left(x, 3 \cdot x - 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}{3 + x \cdot \left(9 \cdot x - 12\right)}\]
  5. Taylor expanded around 0 0.1

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

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

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

Reproduce

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