Average Error: 0.3 → 0.2
Time: 2.8s
Precision: 64
\[\left(3 \cdot \left(2 - x \cdot 3\right)\right) \cdot x\]
\[x \cdot \left(6 - 9 \cdot x\right) + x \cdot \mathsf{fma}\left(-x, 9, x \cdot 9\right)\]
\left(3 \cdot \left(2 - x \cdot 3\right)\right) \cdot x
x \cdot \left(6 - 9 \cdot x\right) + x \cdot \mathsf{fma}\left(-x, 9, x \cdot 9\right)
double f(double x) {
        double r800924 = 3.0;
        double r800925 = 2.0;
        double r800926 = x;
        double r800927 = r800926 * r800924;
        double r800928 = r800925 - r800927;
        double r800929 = r800924 * r800928;
        double r800930 = r800929 * r800926;
        return r800930;
}

double f(double x) {
        double r800931 = x;
        double r800932 = 6.0;
        double r800933 = 9.0;
        double r800934 = r800933 * r800931;
        double r800935 = r800932 - r800934;
        double r800936 = r800931 * r800935;
        double r800937 = -r800931;
        double r800938 = r800931 * r800933;
        double r800939 = fma(r800937, r800933, r800938);
        double r800940 = r800931 * r800939;
        double r800941 = r800936 + r800940;
        return r800941;
}

Error

Bits error versus x

Target

Original0.3
Target0.2
Herbie0.2
\[6 \cdot x - 9 \cdot \left(x \cdot x\right)\]

Derivation

  1. Initial program 0.3

    \[\left(3 \cdot \left(2 - x \cdot 3\right)\right) \cdot x\]
  2. Taylor expanded around 0 0.2

    \[\leadsto \color{blue}{6 \cdot x - 9 \cdot {x}^{2}}\]
  3. Simplified0.2

    \[\leadsto \color{blue}{x \cdot \left(6 - 9 \cdot x\right)}\]
  4. Using strategy rm
  5. Applied add-sqr-sqrt0.7

    \[\leadsto x \cdot \left(\color{blue}{\sqrt{6} \cdot \sqrt{6}} - 9 \cdot x\right)\]
  6. Applied prod-diff0.7

    \[\leadsto x \cdot \color{blue}{\left(\mathsf{fma}\left(\sqrt{6}, \sqrt{6}, -x \cdot 9\right) + \mathsf{fma}\left(-x, 9, x \cdot 9\right)\right)}\]
  7. Applied distribute-lft-in0.7

    \[\leadsto \color{blue}{x \cdot \mathsf{fma}\left(\sqrt{6}, \sqrt{6}, -x \cdot 9\right) + x \cdot \mathsf{fma}\left(-x, 9, x \cdot 9\right)}\]
  8. Simplified0.2

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

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

Reproduce

herbie shell --seed 2020057 +o rules:numerics
(FPCore (x)
  :name "Diagrams.Tangent:$catParam from diagrams-lib-1.3.0.3, E"
  :precision binary64

  :herbie-target
  (- (* 6 x) (* 9 (* x x)))

  (* (* 3 (- 2 (* x 3))) x))