Average Error: 0.3 → 0.1
Time: 8.9s
Precision: 64
\[\left(3 \cdot \left(2 - x \cdot 3\right)\right) \cdot x\]
\[\mathsf{fma}\left(x, 6, -\left(x \cdot x\right) \cdot 9\right)\]
\left(3 \cdot \left(2 - x \cdot 3\right)\right) \cdot x
\mathsf{fma}\left(x, 6, -\left(x \cdot x\right) \cdot 9\right)
double f(double x) {
        double r30793762 = 3.0;
        double r30793763 = 2.0;
        double r30793764 = x;
        double r30793765 = r30793764 * r30793762;
        double r30793766 = r30793763 - r30793765;
        double r30793767 = r30793762 * r30793766;
        double r30793768 = r30793767 * r30793764;
        return r30793768;
}

double f(double x) {
        double r30793769 = x;
        double r30793770 = 6.0;
        double r30793771 = r30793769 * r30793769;
        double r30793772 = 9.0;
        double r30793773 = r30793771 * r30793772;
        double r30793774 = -r30793773;
        double r30793775 = fma(r30793769, r30793770, r30793774);
        return r30793775;
}

Error

Bits error versus x

Target

Original0.3
Target0.2
Herbie0.1
\[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 6 - \left(x \cdot x\right) \cdot 9}\]
  4. Using strategy rm
  5. Applied fma-neg0.1

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

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

Reproduce

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

  :herbie-target
  (- (* 6.0 x) (* 9.0 (* x x)))

  (* (* 3.0 (- 2.0 (* x 3.0))) x))