Average Error: 0.2 → 0.1
Time: 9.1s
Precision: 64
\[\left(3 \cdot \left(2 - x \cdot 3\right)\right) \cdot x\]
\[\mathsf{fma}\left(-9, x \cdot x, 9 \cdot \left(x \cdot x\right)\right) + \mathsf{fma}\left(x, 6, -9 \cdot \left(x \cdot x\right)\right)\]
\left(3 \cdot \left(2 - x \cdot 3\right)\right) \cdot x
\mathsf{fma}\left(-9, x \cdot x, 9 \cdot \left(x \cdot x\right)\right) + \mathsf{fma}\left(x, 6, -9 \cdot \left(x \cdot x\right)\right)
double f(double x) {
        double r29394191 = 3.0;
        double r29394192 = 2.0;
        double r29394193 = x;
        double r29394194 = r29394193 * r29394191;
        double r29394195 = r29394192 - r29394194;
        double r29394196 = r29394191 * r29394195;
        double r29394197 = r29394196 * r29394193;
        return r29394197;
}

double f(double x) {
        double r29394198 = 9.0;
        double r29394199 = -r29394198;
        double r29394200 = x;
        double r29394201 = r29394200 * r29394200;
        double r29394202 = r29394198 * r29394201;
        double r29394203 = fma(r29394199, r29394201, r29394202);
        double r29394204 = 6.0;
        double r29394205 = -r29394202;
        double r29394206 = fma(r29394200, r29394204, r29394205);
        double r29394207 = r29394203 + r29394206;
        return r29394207;
}

Error

Bits error versus x

Target

Original0.2
Target0.2
Herbie0.1
\[6 \cdot x - 9 \cdot \left(x \cdot x\right)\]

Derivation

  1. Initial program 0.2

    \[\left(3 \cdot \left(2 - x \cdot 3\right)\right) \cdot x\]
  2. Taylor expanded around 0 0.2

    \[\leadsto \color{blue}{6 \cdot x - 9 \cdot {x}^{2}}\]
  3. Simplified0.2

    \[\leadsto \color{blue}{x \cdot 6 - \left(x \cdot x\right) \cdot 9}\]
  4. Using strategy rm
  5. Applied prod-diff0.1

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

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

Reproduce

herbie shell --seed 2019172 +o rules:numerics
(FPCore (x)
  :name "Diagrams.Tangent:$catParam from diagrams-lib-1.3.0.3, E"

  :herbie-target
  (- (* 6.0 x) (* 9.0 (* x x)))

  (* (* 3.0 (- 2.0 (* x 3.0))) x))