Average Error: 0.2 → 0.1
Time: 21.2s
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 r546843 = 3.0;
        double r546844 = x;
        double r546845 = r546844 * r546843;
        double r546846 = r546845 * r546844;
        double r546847 = 4.0;
        double r546848 = r546844 * r546847;
        double r546849 = r546846 - r546848;
        double r546850 = 1.0;
        double r546851 = r546849 + r546850;
        double r546852 = r546843 * r546851;
        return r546852;
}

double f(double x) {
        double r546853 = x;
        double r546854 = 9.0;
        double r546855 = r546853 * r546854;
        double r546856 = 12.0;
        double r546857 = r546855 - r546856;
        double r546858 = 3.0;
        double r546859 = fma(r546853, r546857, r546858);
        return r546859;
}

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, 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 2019326 +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)))