Average Error: 0.2 → 0.1
Time: 16.6s
Precision: 64
\[3.0 \cdot \left(\left(\left(x \cdot 3.0\right) \cdot x - x \cdot 4.0\right) + 1.0\right)\]
\[\mathsf{fma}\left(x, x \cdot 9.0 - 12.0, 3.0\right)\]
3.0 \cdot \left(\left(\left(x \cdot 3.0\right) \cdot x - x \cdot 4.0\right) + 1.0\right)
\mathsf{fma}\left(x, x \cdot 9.0 - 12.0, 3.0\right)
double f(double x) {
        double r32903096 = 3.0;
        double r32903097 = x;
        double r32903098 = r32903097 * r32903096;
        double r32903099 = r32903098 * r32903097;
        double r32903100 = 4.0;
        double r32903101 = r32903097 * r32903100;
        double r32903102 = r32903099 - r32903101;
        double r32903103 = 1.0;
        double r32903104 = r32903102 + r32903103;
        double r32903105 = r32903096 * r32903104;
        return r32903105;
}

double f(double x) {
        double r32903106 = x;
        double r32903107 = 9.0;
        double r32903108 = r32903106 * r32903107;
        double r32903109 = 12.0;
        double r32903110 = r32903108 - r32903109;
        double r32903111 = 3.0;
        double r32903112 = fma(r32903106, r32903110, r32903111);
        return r32903112;
}

Error

Bits error versus x

Target

Original0.2
Target0.1
Herbie0.1
\[3.0 + \left(\left(9.0 \cdot x\right) \cdot x - 12.0 \cdot x\right)\]

Derivation

  1. Initial program 0.2

    \[3.0 \cdot \left(\left(\left(x \cdot 3.0\right) \cdot x - x \cdot 4.0\right) + 1.0\right)\]
  2. Taylor expanded around 0 0.1

    \[\leadsto \color{blue}{\left(9.0 \cdot {x}^{2} + 3.0\right) - 12.0 \cdot x}\]
  3. Simplified0.1

    \[\leadsto \color{blue}{\mathsf{fma}\left(9.0, x \cdot x, 3.0\right) - x \cdot 12.0}\]
  4. Taylor expanded around 0 0.1

    \[\leadsto \color{blue}{\left(9.0 \cdot {x}^{2} + 3.0\right) - 12.0 \cdot x}\]
  5. Simplified0.1

    \[\leadsto \color{blue}{\mathsf{fma}\left(x, 9.0 \cdot x - 12.0, 3.0\right)}\]
  6. Final simplification0.1

    \[\leadsto \mathsf{fma}\left(x, x \cdot 9.0 - 12.0, 3.0\right)\]

Reproduce

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