Average Error: 0.1 → 0.1
Time: 16.3s
Precision: 64
\[3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right)\]
\[\mathsf{fma}\left(x \cdot x, 9, 3\right) - 12 \cdot x\]
3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right)
\mathsf{fma}\left(x \cdot x, 9, 3\right) - 12 \cdot x
double f(double x) {
        double r32681604 = 3.0;
        double r32681605 = x;
        double r32681606 = r32681605 * r32681604;
        double r32681607 = r32681606 * r32681605;
        double r32681608 = 4.0;
        double r32681609 = r32681605 * r32681608;
        double r32681610 = r32681607 - r32681609;
        double r32681611 = 1.0;
        double r32681612 = r32681610 + r32681611;
        double r32681613 = r32681604 * r32681612;
        return r32681613;
}

double f(double x) {
        double r32681614 = x;
        double r32681615 = r32681614 * r32681614;
        double r32681616 = 9.0;
        double r32681617 = 3.0;
        double r32681618 = fma(r32681615, r32681616, r32681617);
        double r32681619 = 12.0;
        double r32681620 = r32681619 * r32681614;
        double r32681621 = r32681618 - r32681620;
        return r32681621;
}

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

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

Reproduce

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