Average Error: 0.2 → 0.1
Time: 45.9s
Precision: 64
\[3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right)\]
\[\mathsf{fma}\left(x \cdot 9, x, 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 \cdot 9, x, 3 - 12 \cdot x\right)
double f(double x) {
        double r32580292 = 3.0;
        double r32580293 = x;
        double r32580294 = r32580293 * r32580292;
        double r32580295 = r32580294 * r32580293;
        double r32580296 = 4.0;
        double r32580297 = r32580293 * r32580296;
        double r32580298 = r32580295 - r32580297;
        double r32580299 = 1.0;
        double r32580300 = r32580298 + r32580299;
        double r32580301 = r32580292 * r32580300;
        return r32580301;
}

double f(double x) {
        double r32580302 = x;
        double r32580303 = 9.0;
        double r32580304 = r32580302 * r32580303;
        double r32580305 = 3.0;
        double r32580306 = 12.0;
        double r32580307 = r32580306 * r32580302;
        double r32580308 = r32580305 - r32580307;
        double r32580309 = fma(r32580304, r32580302, r32580308);
        return r32580309;
}

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

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

Reproduce

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