Average Error: 0.1 → 0.1
Time: 12.1s
Precision: 64
\[3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right)\]
\[\mathsf{fma}\left(x, \mathsf{fma}\left(x, 9, -12\right), 3\right)\]
3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right)
\mathsf{fma}\left(x, \mathsf{fma}\left(x, 9, -12\right), 3\right)
double f(double x) {
        double r454010 = 3.0;
        double r454011 = x;
        double r454012 = r454011 * r454010;
        double r454013 = r454012 * r454011;
        double r454014 = 4.0;
        double r454015 = r454011 * r454014;
        double r454016 = r454013 - r454015;
        double r454017 = 1.0;
        double r454018 = r454016 + r454017;
        double r454019 = r454010 * r454018;
        return r454019;
}

double f(double x) {
        double r454020 = x;
        double r454021 = 9.0;
        double r454022 = 12.0;
        double r454023 = -r454022;
        double r454024 = fma(r454020, r454021, r454023);
        double r454025 = 3.0;
        double r454026 = fma(r454020, r454024, r454025);
        return r454026;
}

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}{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}{\mathsf{fma}\left(x, \mathsf{fma}\left(x, 9, -12\right), 3\right)}\]
  5. Final simplification0.1

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

Reproduce

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