Average Error: 0.2 → 0.1
Time: 18.0s
Precision: 64
\[3.0 \cdot \left(\left(\left(x \cdot 3.0\right) \cdot x - x \cdot 4.0\right) + 1.0\right)\]
\[\mathsf{fma}\left(3.0, 1.0, \left(x \cdot 9.0 - 12.0\right) \cdot x\right)\]
3.0 \cdot \left(\left(\left(x \cdot 3.0\right) \cdot x - x \cdot 4.0\right) + 1.0\right)
\mathsf{fma}\left(3.0, 1.0, \left(x \cdot 9.0 - 12.0\right) \cdot x\right)
double f(double x) {
        double r25856255 = 3.0;
        double r25856256 = x;
        double r25856257 = r25856256 * r25856255;
        double r25856258 = r25856257 * r25856256;
        double r25856259 = 4.0;
        double r25856260 = r25856256 * r25856259;
        double r25856261 = r25856258 - r25856260;
        double r25856262 = 1.0;
        double r25856263 = r25856261 + r25856262;
        double r25856264 = r25856255 * r25856263;
        return r25856264;
}

double f(double x) {
        double r25856265 = 3.0;
        double r25856266 = 1.0;
        double r25856267 = x;
        double r25856268 = 9.0;
        double r25856269 = r25856267 * r25856268;
        double r25856270 = 12.0;
        double r25856271 = r25856269 - r25856270;
        double r25856272 = r25856271 * r25856267;
        double r25856273 = fma(r25856265, r25856266, r25856272);
        return r25856273;
}

Error

Bits error versus x

Target

Original0.2
Target0.1
Herbie0.1
\[3.0 + \left(\left(9.0 \cdot x\right) \cdot x - 12.0 \cdot x\right)\]

Derivation

  1. Initial program 0.2

    \[3.0 \cdot \left(\left(\left(x \cdot 3.0\right) \cdot x - x \cdot 4.0\right) + 1.0\right)\]
  2. Simplified0.2

    \[\leadsto \color{blue}{\mathsf{fma}\left(3.0, 1.0, \left(x \cdot 3.0 - 4.0\right) \cdot \left(x \cdot 3.0\right)\right)}\]
  3. Taylor expanded around 0 0.1

    \[\leadsto \mathsf{fma}\left(3.0, 1.0, \color{blue}{9.0 \cdot {x}^{2} - 12.0 \cdot x}\right)\]
  4. Simplified0.1

    \[\leadsto \mathsf{fma}\left(3.0, 1.0, \color{blue}{x \cdot \left(9.0 \cdot x - 12.0\right)}\right)\]
  5. Final simplification0.1

    \[\leadsto \mathsf{fma}\left(3.0, 1.0, \left(x \cdot 9.0 - 12.0\right) \cdot x\right)\]

Reproduce

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