Average Error: 0.1 → 0.1
Time: 18.9s
Precision: 64
\[3.0 \cdot \left(\left(\left(x \cdot 3.0\right) \cdot x - x \cdot 4.0\right) + 1.0\right)\]
\[\mathsf{fma}\left(9.0, x \cdot x, 3.0 - x \cdot 12.0\right)\]
3.0 \cdot \left(\left(\left(x \cdot 3.0\right) \cdot x - x \cdot 4.0\right) + 1.0\right)
\mathsf{fma}\left(9.0, x \cdot x, 3.0 - x \cdot 12.0\right)
double f(double x) {
        double r31396157 = 3.0;
        double r31396158 = x;
        double r31396159 = r31396158 * r31396157;
        double r31396160 = r31396159 * r31396158;
        double r31396161 = 4.0;
        double r31396162 = r31396158 * r31396161;
        double r31396163 = r31396160 - r31396162;
        double r31396164 = 1.0;
        double r31396165 = r31396163 + r31396164;
        double r31396166 = r31396157 * r31396165;
        return r31396166;
}

double f(double x) {
        double r31396167 = 9.0;
        double r31396168 = x;
        double r31396169 = r31396168 * r31396168;
        double r31396170 = 3.0;
        double r31396171 = 12.0;
        double r31396172 = r31396168 * r31396171;
        double r31396173 = r31396170 - r31396172;
        double r31396174 = fma(r31396167, r31396169, r31396173);
        return r31396174;
}

Error

Bits error versus x

Target

Original0.1
Target0.1
Herbie0.1
\[3.0 + \left(\left(9.0 \cdot x\right) \cdot x - 12.0 \cdot x\right)\]

Derivation

  1. Initial program 0.1

    \[3.0 \cdot \left(\left(\left(x \cdot 3.0\right) \cdot x - x \cdot 4.0\right) + 1.0\right)\]
  2. Taylor expanded around 0 0.1

    \[\leadsto \color{blue}{\left(9.0 \cdot {x}^{2} + 3.0\right) - 12.0 \cdot x}\]
  3. Simplified0.1

    \[\leadsto \color{blue}{\mathsf{fma}\left(9.0, x \cdot x, 3.0\right) - x \cdot 12.0}\]
  4. Using strategy rm
  5. Applied fma-udef0.1

    \[\leadsto \color{blue}{\left(9.0 \cdot \left(x \cdot x\right) + 3.0\right)} - x \cdot 12.0\]
  6. Applied associate--l+0.1

    \[\leadsto \color{blue}{9.0 \cdot \left(x \cdot x\right) + \left(3.0 - x \cdot 12.0\right)}\]
  7. Using strategy rm
  8. Applied fma-def0.1

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

    \[\leadsto \mathsf{fma}\left(9.0, x \cdot x, 3.0 - x \cdot 12.0\right)\]

Reproduce

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