Average Error: 0.1 → 0.1
Time: 13.2s
Precision: 64
\[3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right)\]
\[\left(-12\right) \cdot x + \mathsf{fma}\left(9, x \cdot x, 3\right)\]
3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right)
\left(-12\right) \cdot x + \mathsf{fma}\left(9, x \cdot x, 3\right)
double f(double x) {
        double r29573299 = 3.0;
        double r29573300 = x;
        double r29573301 = r29573300 * r29573299;
        double r29573302 = r29573301 * r29573300;
        double r29573303 = 4.0;
        double r29573304 = r29573300 * r29573303;
        double r29573305 = r29573302 - r29573304;
        double r29573306 = 1.0;
        double r29573307 = r29573305 + r29573306;
        double r29573308 = r29573299 * r29573307;
        return r29573308;
}

double f(double x) {
        double r29573309 = 12.0;
        double r29573310 = -r29573309;
        double r29573311 = x;
        double r29573312 = r29573310 * r29573311;
        double r29573313 = 9.0;
        double r29573314 = r29573311 * r29573311;
        double r29573315 = 3.0;
        double r29573316 = fma(r29573313, r29573314, r29573315);
        double r29573317 = r29573312 + r29573316;
        return r29573317;
}

Error

Bits error versus x

Target

Original0.1
Target0.1
Herbie0.1
\[3 + \left(\left(9 \cdot x\right) \cdot x - 12 \cdot x\right)\]

Derivation

  1. Initial program 0.1

    \[3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right)\]
  2. Simplified0.1

    \[\leadsto \color{blue}{\mathsf{fma}\left(x, 3 \cdot x - 4, 1\right) \cdot 3}\]
  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}{3 + x \cdot \left(9 \cdot x - 12\right)}\]
  5. Using strategy rm
  6. Applied sub-neg0.1

    \[\leadsto 3 + x \cdot \color{blue}{\left(9 \cdot x + \left(-12\right)\right)}\]
  7. Applied distribute-lft-in0.1

    \[\leadsto 3 + \color{blue}{\left(x \cdot \left(9 \cdot x\right) + x \cdot \left(-12\right)\right)}\]
  8. Applied associate-+r+0.1

    \[\leadsto \color{blue}{\left(3 + x \cdot \left(9 \cdot x\right)\right) + x \cdot \left(-12\right)}\]
  9. Simplified0.1

    \[\leadsto \color{blue}{\mathsf{fma}\left(9, x \cdot x, 3\right)} + x \cdot \left(-12\right)\]
  10. Final simplification0.1

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

Reproduce

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