Average Error: 0.2 → 0.1
Time: 9.2s
Precision: 64
\[3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right)\]
\[3 + \mathsf{fma}\left(x, 9 \cdot x, x \cdot \left(-12\right)\right)\]
3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right)
3 + \mathsf{fma}\left(x, 9 \cdot x, x \cdot \left(-12\right)\right)
double f(double x) {
        double r1154225 = 3.0;
        double r1154226 = x;
        double r1154227 = r1154226 * r1154225;
        double r1154228 = r1154227 * r1154226;
        double r1154229 = 4.0;
        double r1154230 = r1154226 * r1154229;
        double r1154231 = r1154228 - r1154230;
        double r1154232 = 1.0;
        double r1154233 = r1154231 + r1154232;
        double r1154234 = r1154225 * r1154233;
        return r1154234;
}

double f(double x) {
        double r1154235 = 3.0;
        double r1154236 = x;
        double r1154237 = 9.0;
        double r1154238 = r1154237 * r1154236;
        double r1154239 = 12.0;
        double r1154240 = -r1154239;
        double r1154241 = r1154236 * r1154240;
        double r1154242 = fma(r1154236, r1154238, r1154241);
        double r1154243 = r1154235 + r1154242;
        return r1154243;
}

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. Simplified0.1

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

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

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

Reproduce

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