Average Error: 0.2 → 0.1
Time: 20.1s
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 r513769 = 3.0;
        double r513770 = x;
        double r513771 = r513770 * r513769;
        double r513772 = r513771 * r513770;
        double r513773 = 4.0;
        double r513774 = r513770 * r513773;
        double r513775 = r513772 - r513774;
        double r513776 = 1.0;
        double r513777 = r513775 + r513776;
        double r513778 = r513769 * r513777;
        return r513778;
}

double f(double x) {
        double r513779 = x;
        double r513780 = 9.0;
        double r513781 = r513780 * r513779;
        double r513782 = 12.0;
        double r513783 = r513781 - r513782;
        double r513784 = 3.0;
        double r513785 = fma(r513779, r513783, r513784);
        return r513785;
}

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}{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, 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 2019199 +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)))