Average Error: 0.2 → 0.1
Time: 23.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 - 12, 3\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 - 12, 3\right)
double f(double x) {
        double r395085 = 3.0;
        double r395086 = x;
        double r395087 = r395086 * r395085;
        double r395088 = r395087 * r395086;
        double r395089 = 4.0;
        double r395090 = r395086 * r395089;
        double r395091 = r395088 - r395090;
        double r395092 = 1.0;
        double r395093 = r395091 + r395092;
        double r395094 = r395085 * r395093;
        return r395094;
}

double f(double x) {
        double r395095 = x;
        double r395096 = 9.0;
        double r395097 = r395095 * r395096;
        double r395098 = 12.0;
        double r395099 = r395097 - r395098;
        double r395100 = 3.0;
        double r395101 = fma(r395095, r395099, r395100);
        return r395101;
}

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

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

Reproduce

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