Average Error: 0.1 → 0.1
Time: 14.8s
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 r27975188 = 3.0;
        double r27975189 = x;
        double r27975190 = r27975189 * r27975188;
        double r27975191 = r27975190 * r27975189;
        double r27975192 = 4.0;
        double r27975193 = r27975189 * r27975192;
        double r27975194 = r27975191 - r27975193;
        double r27975195 = 1.0;
        double r27975196 = r27975194 + r27975195;
        double r27975197 = r27975188 * r27975196;
        return r27975197;
}

double f(double x) {
        double r27975198 = x;
        double r27975199 = 9.0;
        double r27975200 = r27975198 * r27975199;
        double r27975201 = 3.0;
        double r27975202 = 12.0;
        double r27975203 = r27975202 * r27975198;
        double r27975204 = r27975201 - r27975203;
        double r27975205 = fma(r27975198, r27975200, r27975204);
        return r27975205;
}

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 2019171 +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)))