Average Error: 0.1 → 0.1
Time: 15.9s
Precision: 64
\[3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right)\]
\[\mathsf{fma}\left(x, x \cdot 9, 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, x \cdot 9, 3 - 12 \cdot x\right)
double f(double x) {
        double r28479340 = 3.0;
        double r28479341 = x;
        double r28479342 = r28479341 * r28479340;
        double r28479343 = r28479342 * r28479341;
        double r28479344 = 4.0;
        double r28479345 = r28479341 * r28479344;
        double r28479346 = r28479343 - r28479345;
        double r28479347 = 1.0;
        double r28479348 = r28479346 + r28479347;
        double r28479349 = r28479340 * r28479348;
        return r28479349;
}

double f(double x) {
        double r28479350 = x;
        double r28479351 = 9.0;
        double r28479352 = r28479350 * r28479351;
        double r28479353 = 3.0;
        double r28479354 = 12.0;
        double r28479355 = r28479354 * r28479350;
        double r28479356 = r28479353 - r28479355;
        double r28479357 = fma(r28479350, r28479352, r28479356);
        return r28479357;
}

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

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

Reproduce

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