Average Error: 0.1 → 0.1
Time: 20.8s
Precision: 64
\[3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right)\]
\[\mathsf{fma}\left(x, x \cdot 9 - 12, 3\right)\]
3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right)
\mathsf{fma}\left(x, x \cdot 9 - 12, 3\right)
double f(double x) {
        double r476564 = 3.0;
        double r476565 = x;
        double r476566 = r476565 * r476564;
        double r476567 = r476566 * r476565;
        double r476568 = 4.0;
        double r476569 = r476565 * r476568;
        double r476570 = r476567 - r476569;
        double r476571 = 1.0;
        double r476572 = r476570 + r476571;
        double r476573 = r476564 * r476572;
        return r476573;
}

double f(double x) {
        double r476574 = x;
        double r476575 = 9.0;
        double r476576 = r476574 * r476575;
        double r476577 = 12.0;
        double r476578 = r476576 - r476577;
        double r476579 = 3.0;
        double r476580 = fma(r476574, r476578, r476579);
        return r476580;
}

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. 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, x \cdot 9 - 12, 3\right)}\]
  4. Final simplification0.1

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

Reproduce

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