Average Error: 0.2 → 0.1
Time: 2.2s
Precision: 64
\[3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right)\]
\[\mathsf{fma}\left(x, 9 \cdot x - 12, 3\right)\]
3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right)
\mathsf{fma}\left(x, 9 \cdot x - 12, 3\right)
double f(double x) {
        double r726592 = 3.0;
        double r726593 = x;
        double r726594 = r726593 * r726592;
        double r726595 = r726594 * r726593;
        double r726596 = 4.0;
        double r726597 = r726593 * r726596;
        double r726598 = r726595 - r726597;
        double r726599 = 1.0;
        double r726600 = r726598 + r726599;
        double r726601 = r726592 * r726600;
        return r726601;
}

double f(double x) {
        double r726602 = x;
        double r726603 = 9.0;
        double r726604 = r726603 * r726602;
        double r726605 = 12.0;
        double r726606 = r726604 - r726605;
        double r726607 = 3.0;
        double r726608 = fma(r726602, r726606, r726607);
        return r726608;
}

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. 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}^{2}, 9, 3 - 12 \cdot x\right)}\]
  4. Taylor expanded around 0 0.1

    \[\leadsto \color{blue}{\left(9 \cdot {x}^{2} + 3\right) - 12 \cdot x}\]
  5. Simplified0.1

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

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

Reproduce

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