Average Error: 0.2 → 0.1
Time: 2.5s
Precision: 64
\[3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right)\]
\[\mathsf{fma}\left({x}^{2}, 9, 3 - 12 \cdot x\right)\]
3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right)
\mathsf{fma}\left({x}^{2}, 9, 3 - 12 \cdot x\right)
double f(double x) {
        double r887780 = 3.0;
        double r887781 = x;
        double r887782 = r887781 * r887780;
        double r887783 = r887782 * r887781;
        double r887784 = 4.0;
        double r887785 = r887781 * r887784;
        double r887786 = r887783 - r887785;
        double r887787 = 1.0;
        double r887788 = r887786 + r887787;
        double r887789 = r887780 * r887788;
        return r887789;
}

double f(double x) {
        double r887790 = x;
        double r887791 = 2.0;
        double r887792 = pow(r887790, r887791);
        double r887793 = 9.0;
        double r887794 = 3.0;
        double r887795 = 12.0;
        double r887796 = r887795 * r887790;
        double r887797 = r887794 - r887796;
        double r887798 = fma(r887792, r887793, r887797);
        return r887798;
}

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

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

Reproduce

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