Average Error: 0.2 → 0.1
Time: 2.3s
Precision: 64
\[3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right)\]
\[\mathsf{fma}\left({x}^{2}, 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}^{2}, 9, 3 - 12 \cdot x\right)
double f(double x) {
        double r805910 = 3.0;
        double r805911 = x;
        double r805912 = r805911 * r805910;
        double r805913 = r805912 * r805911;
        double r805914 = 4.0;
        double r805915 = r805911 * r805914;
        double r805916 = r805913 - r805915;
        double r805917 = 1.0;
        double r805918 = r805916 + r805917;
        double r805919 = r805910 * r805918;
        return r805919;
}

double f(double x) {
        double r805920 = x;
        double r805921 = 2.0;
        double r805922 = pow(r805920, r805921);
        double r805923 = 9.0;
        double r805924 = 3.0;
        double r805925 = 12.0;
        double r805926 = r805925 * r805920;
        double r805927 = r805924 - r805926;
        double r805928 = fma(r805922, r805923, r805927);
        return r805928;
}

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. Simplified0.1

    \[\leadsto \color{blue}{\mathsf{fma}\left(x, x \cdot 3 - 4, 1\right) \cdot 3}\]
  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}^{2}, 9, 3 - 12 \cdot x\right)}\]
  5. Final simplification0.1

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

Reproduce

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